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
- Generate a new expo app
- Add
@supabase/supabase-jsas a dependency - Create a supabase client in the main
_layout.tsxfile - Run
npx expo customize metro.config.js - Add
config.resolver.unstable_enablePackageExports = true;tometro.config.js - Add
ios.bundleIdentifiertoapp.json - Run
npx expo run:ios
Repro repo: https://github.com/aldebout/supabase-expo-exports-issue
Expected behavior
No crash
Screenshots
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)
same issue , i update to expo sdk 53.
we’re releasing a
nextversion of supabase-js to try and test out if a fix works: https://github.com/supabase/supabase-js/pull/1395supabase-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:exportsare now enabled by default, making@supabase/supabase-jsand@supabase/realtime-jsunusable 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
wswhich 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”