supabase-js: Can't use with unstable_enablePackageExports metro option (expo)
Cross-posting https://github.com/supabase/realtime-js/issues/415 because I’m not sure you’re monitoring the issues on the other repo 😃
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: 29 (6 by maintainers)
Commits related to this issue
- move /apps/expo to /expo to fix supabase issue https://github.com/supabase/supabase-js/issues/1258 — committed to gianpaj/call-me-please by gianpaj 2 years ago
This fixed the issues I’ve been having:
config.resolver.unstable_conditionNames = [‘require’, ‘default’, ‘browser’]. For me, adding ‘browser’ has fixed it so far.
you saved me, thanks a lot!!
I have no idea. I tried it after everything else had failed. I found some other examples of metro configs on the Expo Discord with more condition names. I added in the condition names that I didn’t have. It worked. Then I removed them individually until I knew it was ‘browser’. If this works for others, maybe someone at Expo can give you an answer as to why.
Yes, that’s correct. Just wanted to confirm this works and send a snippet to fix it here.
I’m able to run it by manually specifying
nodeModulesPathsand settingdisableHierarchicalLookuptotrue(in a monorepo setup).Just stumbled upon this as was facing this issue (using SDK 53 beta). This behavior is expected: Metro’s support for Node‑style conditional exports now strictly honors the configured “conditions” (require, import, etc.) when resolving a package’s exports field, and it will only consider the “browser” entry if you explicitly include “browser” in its condition list.
This change comes from Metro bundler and mentioned as a breaking change https://expo.dev/changelog/sdk-53-beta. Also mentions setting unstable_enablePackageExports: false.
Not sure about expo but with pnpm I can do this and it works
I’ve merged https://github.com/supabase/realtime-js/pull/444 so
2.11.4-next.1will have this code.I do need some help testing this change, if possible do override
realtime-jsinsupabase-jswith this version