supabase / realtime-js

An isomorphic Javascript client for Supabase Realtime server.
https://supabase.com
MIT License
321 stars 58 forks source link

Can't use with unstable_enablePackageExports metro option (expo) #415

Open aldebout opened 3 months ago

aldebout commented 3 months ago

Bug report

Describe the bug

When using @supabase/supabase-js in an expo react native project, if I use the unstable_enablePackageExports with the metro bundler, bundling fails with the following error:

To Reproduce

  1. Generate a new expo app
  2. Add @supabase/supabase-js as a dependency
  3. Create a supabase client in the main _layout.tsx file
  4. Run npx expo customize metro.config.js
  5. Add config.resolver.unstable_enablePackageExports = true; to metro.config.js
  6. Add ios.bundleIdentifier to app.json
  7. Run npx expo run:ios

Repro repo: https://github.com/aldebout/supabase-expo-exports-issue

Expected behavior

No crash

Screenshots

image

System information

Additional information

Opening here because the error message I got in my actual project was

The package at "../../node_modules/@supabase/realtime-js/node_modules/ws/lib/stream.js" attempted to import the Node standard library module "stream".
It failed because the native React runtime does not include the Node standard library.
practiv-wamci commented 2 months ago

Is there any update on this? I've run into the same issue

filipecabaco commented 2 months ago

now that we have native ws support I do think that we can remove ws which seems to be the source of the issue.

https://github.com/supabase/realtime-js/pull/426 here's a branch for us to use for testing to see if we can fix it by removing ws from realtime-js dependencies.

but after removing it I keep getting the same issue and the only dependency that uses it's node_modules/@expo/cli 😞 . what could be the way to fix it?

aldebout commented 1 month ago

@filipecabaco I'm not sure what the next step is, how can I help you?

filipecabaco commented 1 month ago

@aldebout maybe. it seems that the main issue was the fact that we had the ws dependency which created issues with expo. the PR https://github.com/supabase/realtime-js/pull/426 removes said dependency.

could you try to checkout the repo, checkout the branch fix/remove-ws-lib and override the dependency to check if it's not something related to my environment?

aldebout commented 1 month ago

I tried using the branch but I'm having issues because package.json references the build outputs (/dist/...) and they're not in the github source code :/ When you tested locally, did you use npm with overrides or a local link? I've had issues with npm overrides in the past, it might work better with yarn or pnpm.

filipecabaco commented 1 month ago

I need to try it again but if I'm not mistaken I did use overrides... maybe I should just make an example with just realtime-js and expo to make it easier to test out without overrides and just importing the "fix branch"