[SDK 53] "... attempted to import the Node standard library module ..." and other package.json:exports related issues
Minimal reproducible example
https://github.com/nanmon/expo-sdk53-sample
What platform(s) does this occur on?
Android
Where did you reproduce the issue?
in Expo Go
Summary
I'm using supabase and Android bundling fails with the following error
Android Bundling failed 888ms node_modules/expo-router/entry.js (1281 modules)
The package at "node_modules/@supabase/realtime-js/node_modules/ws/lib/websocket.js" attempted to import the Node standard library module "events".
It failed because the native React runtime does not include the Node standard library.
Learn more
The minimal reproducible example just imports the supabase package. Supabase works fine on SDK 52
Environment
expo-env-info 1.2.2 environment info:
System:
OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
Shell: 5.8.1 - /usr/bin/zsh
Binaries:
Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
SDKs:
Android SDK:
API Levels: 26, 31, 33, 34, 35
Build Tools: 26.0.3, 30.0.3, 34.0.0, 35.0.0
System Images: android-26 | Google APIs Intel x86 Atom
npmPackages:
expo: ~53.0.0-preview.11 => 53.0.0-preview.11
expo-router: ~5.0.2-preview.5 => 5.0.2-preview.5
react: 19.0.0 => 19.0.0
react-dom: 19.0.0 => 19.0.0
react-native: 0.79.1 => 0.79.1
react-native-web: ~0.20.0 => 0.20.0
Expo Workflow: managed
Expo Doctor Diagnostics
15/15 checks passed. No issues detected!
Hello!
Could you please provide the steps to reproduce the issue?
Hi @nanmon! Thanks for reporting this issue. Unfortunately, this is related to a 3rd party library which we don't maintain. So there isn't a lot we can do about this.
What's happening is that @supabase/realtime-js is importing ws - a Node-only library used for websockets. Because it's using Node internal modules, which aren't available in React Native / Hermes, it can't be compiled to a working bundle.
I see that there is an open issue related to this on Supabase's repository: https://github.com/supabase/supabase-js/issues/1726 - I also added a comment there.
Will close this issue as this is something we can't fix. Hope this helps!
thanks @byCedric! I find your comment very helpful, I couldn't find the cause of the error by myself and also I'm glad you followed up on supabase's issue
For anyone else getting this kind of error, you can workaround it by disabling unstable_enablePackageExports on metro.config.js
const { getDefaultConfig } = require('expo/metro-config')
/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname)
config.resolver.unstable_enablePackageExports = false
module.exports = config
Still struggling with this issue. Worse because I'm building a vibe-coding tool and a lot of our users' apps use supabase and they will all break after migrating to SDK 53.
I tried disabling unstable_enablePackageExports but that didn't fix it for me unfortunately.
https://github.com/expo/expo/issues/36375#issuecomment-2831021204
We have contacted Supabase to get this resolved asap. Will reopen this issue and pin it to keep you up to date. Right now, we have a plan forward but it still needs to be executed from Supabase's side.
We have contacted Supabase to get this resolved asap. Will reopen this issue and pin it to keep you up to date. Right now, we have a plan forward but it still needs to be executed from Supabase's side.
Is this really a supabase problem?
ws is used in many expo internal packages too, and I use socket.io to connected to my websocket server.
├─┬ @supabase/[email protected]
│ └─┬ @supabase/[email protected]
│ └── [email protected]
├─┬ [email protected]
│ └─┬ @expo/[email protected]
│ ├─┬ @react-native/[email protected]
│ │ └── [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ ├─┬ @react-native/[email protected]
│ │ └─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └── [email protected]
└─┬ [email protected]
└─┬ [email protected]
└── [email protected]
Any person who has managed to solve this? I am getting the same issue
hi there! this is the same issue as https://github.com/supabase/supabase-js/issues/1726
the teams at expo and supabase have been discussing this and a fix is in progress. you can disable the package exports configuration in metro as described here:
// metro.config.js
const { getDefaultConfig } = require('expo/metro-config');
/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);
config.resolver.unstable_enablePackageExports = false;
module.exports = config;
If the impacted package uses package.json:exports and has a browser version available, you can also tell Metro to use this browser version until the package is fixed for React Native.
// metro.config.js
const { getDefaultConfig } = require('expo/metro-config');
/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);
config.resolver.resolveRequest = function packageExportsResolver(context, moduleImport, platform) {
// Use the browser version of the package for React Native
if (moduleImport === '<package>' || moduleImport.startsWith('<package>/')) {
return context.resolveRequest(
{
...context,
unstable_conditionNames: ['browser'],
},
moduleImport,
platform,
);
}
// Fall back to normal resolution
return context.resolveRequest(context, moduleImport, platform);
};
module.exports = config;
Is this really a supabase problem?
ws is used in many expo internal packages too, and I use socket.io to connected to my websocket server.
Unfortunately, yes it is. You are correct that lots of libraries use ws, but that's because there is no native Node WebSocket API. All of the dependencies you listed are dependencies only executed during development in Node, and not being pulled into your bundle on devices.
hi folks!
- see https://github.com/expo/expo/issues/36375#issuecomment-2845231862 for an explanation of how to work around this
- please report any libraries that you have encountered these sorts of errors with in https://github.com/expo/expo/discussions/36551
Supabase released a fix for this issue in @supabase/[email protected]! You can install this exact version and see if this resolves the issue for you.
- https://github.com/supabase/realtime-js/releases/tag/v2.11.8-next.1
- https://github.com/supabase/supabase-js/releases/tag/v2.49.5-next.1
Note, supabase is working on getting this version stable for release. Once that's done, it will be released as a normal stable release.
Closing since the supabase issue is resolved upstream and there don't seem to be more updates needed here