@supabase/supabase-js v2.x fails on React Native (Expo) due to ws module import, even with realtime disabled
Closed this issue · 2 comments
When using @supabase/supabase-js v2.49.8 in a React Native (Expo) project, the app crashes on iOS (and likely Android) with the following error, even when realtime is explicitly disabled and not used anywhere in the code:
Unable to resolve module ws from .../node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js: ws could not be found within the project or in these directories: node_modules
This happens even with the following client config:
export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
auth: {
storage: ExpoSecureStoreAdapter,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
},
realtime: false as any, // also tried { WebSocket: global.WebSocket }
});
- There is no usage of realtime features (no channel, subscribe, or on calls) anywhere in the codebase.
- The issue does not occur on web, where the app loads (even with an invalid API key).
- The issue does occur on iOS (React Native/Expo), where the app fails to load due to the missing ws module.
Steps to Reproduce
- Create a new Expo (React Native) project.
- Install
@supabase/supabase-js@2.49.8. - Set up the Supabase client as shown above, with
realtime: false. - Attempt to use any auth or database method (e.g.,
signInWithPassword,from(...).select()). - App fails to load with the error above.
What I’ve Tried
- Setting
realtime: falsein the client config. - Setting
realtime: { WebSocket: global.WebSocket }in the client config. - Ensuring no direct or indirect usage of realtime features.
- Blocking ws in Metro config.
- Testing the official minimal auth example from Supabase docs (works on web, fails on iOS).
- Confirmed only one version of
@supabase/supabase-jsand@supabase/realtime-jsare installed.
Expected Behavior
- The Supabase client should not attempt to import or require Node.js-only modules like
wsin React Native, especially when realtime is disabled and not used. - Auth and database features should work in React Native as documented.
Environment
@supabase/supabase-js: 2.49.8@supabase/realtime-js: 2.11.2- Expo SDK: (your version here)
- React Native: (your version here)
- iOS Version: (your version here)
- Platform: iOS (Expo Go and/or bare)
Additional Context
- This issue blocks all usage of Supabase JS v2.x in React Native, even for basic auth and database features.
- The same code works fine on web.
@kylesherman if you need an immediate possible fix, it looks like they resolved some ws issues in supabase-js@2.49.9-next.2 - otherwise they'll likely release 2.49.9 this week (only a guess).
Hi @kylesherman we just released the fix in https://github.com/supabase/supabase-js/releases/tag/v2.49.9
This issue is also a duplicate of #1400
