Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use with unstable_enablePackageExports metro option (expo) #1258

Open
2 tasks done
aldebout opened this issue Aug 16, 2024 · 4 comments
Open
2 tasks done

Can't use with unstable_enablePackageExports metro option (expo) #1258

aldebout opened this issue Aug 16, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@aldebout
Copy link

Cross-posting supabase/realtime-js#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

  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.
@aldebout aldebout added the bug Something isn't working label Aug 16, 2024
@practiv-wamci
Copy link

Is there any update on this? I've run into the same issue

@adamwett
Copy link

I've also run into this when trying to use Storybook and Expo.

@marcocondrache
Copy link

I'm able to run it by manually specifying nodeModulesPaths and setting disableHierarchicalLookup to true (in a monorepo setup).

@DanielVolchek
Copy link

I'm able to run it by manually specifying nodeModulesPaths and setting disableHierarchicalLookup to true (in a monorepo setup).

This solution didn't work for me

I was able to fix it by patching @supabase/realtime-js to match supabase/realtime-js#426

patchfile looks like this

diff --git a/dist/module/RealtimeClient.js b/dist/module/RealtimeClient.js
index a8bb0121343481d789acb0248ecbb20c7e4597fe..a299d5b3370b836bdf28307deb7a157c6ccf0bc5 100644
--- a/dist/module/RealtimeClient.js
+++ b/dist/module/RealtimeClient.js
@@ -143,12 +143,6 @@ export default class RealtimeClient {
                 this.conn = null;
             },
         });
-        import('ws').then(({ default: WS }) => {
-            this.conn = new WS(this._endPointURL(), undefined, {
-                headers: this.headers,
-            });
-            this.setupConnection();
-        });
     }
     /**
      * Disconnects the socket.

named patches/@supabase__realtime-js.patch

I then added the following to my package.json (for pnpm)

  "pnpm": {
    "patchedDependencies": {
      "@supabase/realtime-js": "patches/@supabase__realtime-js.patch"
    },
    "overrides": {
      "@supabase/realtime-js>ws": "-" 
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants