electric-sql / electric

Sync little subsets of your Postgres data into local apps and services.
https://electric-sql.com
Apache License 2.0
6.05k stars 139 forks source link

failed to use pglite as driver with expo web #1423

Closed MJRT closed 1 month ago

MJRT commented 2 months ago

I'm tried to pick up examples/web-pglite merge to examples/expo but failed.

console output:

AppEntry.bundle:87829 
Uncaught Syntax Error: Cannot use 'import.meta' outside a module

version: expo sdk51, react-native-web 0.19.10, electric-sql 0.12.0, pglite 0.1.5

Here are my modification steps:

  1. I'm used examples/expo as basement, and mkdir ./src/ElectricProvider
  2. move ./ElectricProvider.tsx to ./src/ElectricProvider/index.tsx
  3. move web-pglite-ElectricProvider.tsx to ./src/ElectricProvider/index.web.tsx
  4. change ./* to ../* in index.tsx and index.web.tsx
  5. install expo web dependences: npx expo install react-native-web react-dom @expo/metro-runtime
  6. set "target": "es2020", "module": "esnext", in tsconfig.json

After coded, expo go is still right on my android phone, but web page is blank page with console error.

I tried some solutions from chatgpt and Google but they are still not work, and would like to know how to use it on expo web.

linear[bot] commented 2 months ago

VAX-2006 failed to use pglite as driver with expo web

MJRT commented 1 month ago

After investigated, expo web (sdk51) use metro as bundler, but metro is not support ESM now (Support ESM react-native.config files · Issue #2167 · react-native-community/cli (github.com))

I tried use babel-plugin-transform-import-meta and transform-dirname-filename as babel transform plugin, but it's still failed.

Does anyone know how to make it compatible with CommonJS? I think this could further enhance Electric-sql's influence in the community.

MJRT commented 1 month ago

this repo can reproduce easily, https://github.com/MJRT/import-meta-url-error-on-web

KyleAMathews commented 1 month ago

👋 we've been working the last month on a rebuild of the Electric server over at a temporary repo https://github.com/electric-sql/electric-next/

You can read more about why we made the decision at https://next.electric-sql.com/about

We're really excited about all the new possibilities the new server brings and we hope you'll check it out soon and give us your feedback.

We're now moving the temporary repo back here. As part of that migration we're closing all the old issues and PRs. We really appreciate you taking the time to investigate and report the bug!