realtime-js: Can't use with unstable_enablePackageExports metro option (expo)

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

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

  • OS: macOS
  • Version of supabase-js: 2.45.1
  • Version of Node.js: 20.16.0

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.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 19
  • Comments: 26 (7 by maintainers)

Most upvoted comments

same issue , i update to expo sdk 53.

we’re releasing a next version of supabase-js to try and test out if a fix works: https://github.com/supabase/supabase-js/pull/1395

supabase-js@2.49.5-next.2 appears to fix the issue for me. Thanks!

Unfortunately, this is still an issue due to the inlining of import('ws') here. Starting from Expo SDK 53 - package.json:exports are now enabled by default, making @supabase/supabase-js and @supabase/realtime-js unusable with the default settings.

Related: https://github.com/expo/expo/issues/36375

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?

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”