tinyplex / tinybase

The reactive data store for local‑first apps.
https://tinybase.org
MIT License
3.71k stars 77 forks source link

Expo Web export fails #100

Closed shaneosullivan closed 11 months ago

shaneosullivan commented 11 months ago

Describe the bug

Using ExpoSqlitePersister works fine at runtime in the iOS Simulator. However when exporting to web using

npx expo export -p web

the following error is seen

Screenshot 2023-10-22 at 11 28 59

Note that the Tinybase code is imported as follows:


import { createStore } from "tinybase";
import {
  createExpoSqlitePersister,
  ExpoSqlitePersister,
} from "tinybase/lib/persisters/persister-expo-sqlite";

and that if the persister is not imported, then the npx expo export -p web command runs correctly.

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

In an Expo app, create a standalone file, e.g. db.ts.

At the top of the file add

import { createStore } from "tinybase";
import {
  createExpoSqlitePersister,
  ExpoSqlitePersister,
} from "tinybase/lib/persisters/persister-expo-sqlite";

Now try to run the CLI command

npx expo export -p web

Note that it fails.

Remove the second import, and run the CLI command again. Note that it succeeds

Expected behavior

I expected the web export to succeed, but instead it fails.

Screenshots or Videos

No response

Platform

Additional context

No response

jamesgpearce commented 11 months ago

That error message suggests there is a main field in the TinyBase package.json, but... there is not :/

shaneosullivan commented 11 months ago

Yes, hence my confusion :-)

On Sun 22 Oct 2023 at 14:14, James Pearce @.***> wrote:

That error message suggests there is a main field in the TinyBase package.json, but... there is not :/

— Reply to this email directly, view it on GitHub https://github.com/tinyplex/tinybase/issues/100#issuecomment-1774092839, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMBYU7VCOWAD4S5QV3I5LYAUL4FAVCNFSM6AAAAAA6KZ2XRGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZUGA4TEOBTHE . You are receiving this because you authored the thread.Message ID: @.***>

jamesgpearce commented 11 months ago

I find that npm run web works fine. Does it for you? I guess that's webpack maybe.

But I can repro when I enable metro for web in the app.json. BRB.

jamesgpearce commented 11 months ago

Try adding "main": "./lib/tinybase.js" to the top of the package.json in node_modules/tinybase... does that work for you?

jamesgpearce commented 11 months ago

Well I'm assuming it does. So I rolled a new release v4.3.20 with that fix in. Please try it out!

jamesgpearce commented 11 months ago

This broke some other resolution use-cases, so rolled v4.3.21 to hopefully get the best of both worlds.

shaneosullivan commented 11 months ago

That fixes it!