supabase-js: 2.49.9 breaks application code on Vercel (error 500)

Bug report

Describe the bug

    at (../../../../../node_modules/.pnpm/ws@8.18.2/node_modules/ws/browser.js:4:8)
    at (../../../../../node_modules/.pnpm/@supabase+realtime-js@2.11.9/node_modules/@supabase/realtime-js/src/RealtimeClient.ts:222:20)
    at (../../../../../node_modules/.pnpm/@supabase+realtime-js@2.11.9/node_modules/@supabase/realtime-js/src/RealtimeChannel.ts:218:18)

and the app errors with status 500

To Reproduce

Adding later

Expected behavior

I have updated from 2.49.8

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • Version of supabase-js: [e.g. 2.49.9]
  • Version of Node.js: [e.g. 22.X] (vercel)

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 3
  • Comments: 48 (8 by maintainers)

Most upvoted comments

Thanks @GBarb0 for reporting that latest next version fixed the warning.

We’re working on identifying the issue with realtime subscriptions not firing.

Thanks.

The fix just got released as v2.50.1.

I’m having this same issue with anything above 2.49.8 using Solid-Start.

Here are my logs when upgrading to either 49.9 or 50:

node_modules/.pnpm/@supabase+supabase-js@2.50.0/node_modules/@supabase/supabase-js/dist/module/SupabaseClient.js (1:16): Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/.pnpm/@supabase+supabase-js@2.50.0/node_modules/@supabase/supabase-js/dist/module/SupabaseClient.js (1:24): Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/.pnpm/@supabase+auth-js@2.70.0/node_modules/@supabase/auth-js/dist/module/GoTrueAdminApi.js (1:13): Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/.pnpm/@supabase+auth-js@2.70.0/node_modules/@supabase/auth-js/dist/module/GoTrueAdminApi.js (1:21): Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/.pnpm/@supabase+functions-js@2.4.4/node_modules/@supabase/functions-js/dist/module/FunctionsClient.js (1:16): Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/.pnpm/@supabase+functions-js@2.4.4/node_modules/@supabase/functions-js/dist/module/FunctionsClient.js (1:24): Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/.pnpm/@supabase+supabase-js@2.50.0/node_modules/@supabase/supabase-js/dist/module/lib/fetch.js (1:16): Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/.pnpm/@supabase+supabase-js@2.50.0/node_modules/@supabase/supabase-js/dist/module/lib/fetch.js (1:24): Error when using sourcemap for reporting an error: Can't resolve original location of error.

2.49.8 works fine though

next.config.ts

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'lh3.googleusercontent.com',
      },
    ],
  },
  webpack: (config) => {
    // Configure webpack to prefer ESM builds for browser environments
    config.resolve.mainFields = ['browser', 'module', 'main'];
    
    // Force webpack to use browser conditions for exports field resolution
    config.resolve.conditionNames = ['browser', 'module', 'import', 'default'];
    
    return config;
  },
};

export default nextConfig;

today: version 2.49.10 works with this nextconfig

i made a PR: https://github.com/supabase/realtime-js/pull/481

I ask the community for help in analyzing the fetch solution I proposed.

if you consider that new function has strong security implications in spite of being with hardcoded strings, you can ignore it, but if you consider it viable, let me know to upload a new PR

resume:

 /**
   * Use either custom fetch, if provided, or default fetch to make HTTP requests
   *
   * @internal
   */
  _resolveFetch = (customFetch?: Fetch): Fetch => {
    let _fetch: Fetch
    if (customFetch) {
      _fetch = customFetch
    } else if (typeof fetch === 'undefined') {
      _fetch = (...args) => {
        // Try dynamic import with different strategies based on environment
        return this._attemptNodeFetch(args)
      }
    } else {
      _fetch = fetch
    }
    return (...args) => _fetch(...args)
  }

  /**
   * Attempts to load node-fetch with environment-specific strategies
   * @internal
   */
  private async _attemptNodeFetch(args: Parameters<Fetch>): Promise<Response> {
    // Strategy 1: Try new Function() approach (works in most environments)
    try {
      if (this._canUseFunction()) {
        const dynamicImport = new Function(
          'specifier',
          'return import(specifier)'
        )
        const module = await dynamicImport('@supabase/node-fetch')
        return module.default(...args)
      }
    } catch (error) {
      // Continue to next strategy
    }

    // Strategy 2: Direct import (may cause webpack warnings but works in Edge environments)
    try {
      // @ts-ignore - Dynamic import fallback for Edge environments
      const module = await import('@supabase/node-fetch')
      return (module.default as Fetch)(...args)
    } catch (importError) {
      // Continue to next strategy
    }

    // Strategy 3: Fallback to require for legacy Node.js environments
    try {
      if (this._canUseFunction()) {
        const dynamicRequire = new Function(
          'specifier',
          'return require(specifier)'
        )
        const nodeFetch = dynamicRequire('@supabase/node-fetch')
        return Promise.resolve((nodeFetch.default || nodeFetch)(...args))
      } else {
        // Direct require fallback (works in some Node.js environments)
        const nodeFetch = require('@supabase/node-fetch')
        return Promise.resolve((nodeFetch.default || nodeFetch)(...args))
      }
    } catch (requireError) {
      // All strategies failed
      throw new Error(
        'fetch polyfill required: install @supabase/node-fetch or use Node.js 18+. ' +
          'Current environment does not support dynamic imports or require.'
      )
    }
  }

  /**
   * Checks if new Function() is available (CSP restrictions)
   * @internal
   */
  private _canUseFunction(): boolean {
    try {
      new Function('return true')()
      return true
    } catch {
      return false
    }
  }

thank you! that’s an extremely useful discovery! we might need to do the same fix we did for WS but now one for this fetch lib 😓

are you able to provide some example code so we can replica the issue?

also reopening this issue

Hey all, could you you please try out using v2.50.1-next.6 and let me know if that fixes your issue?

Thanks.

I had this error too:

../../node_modules/.pnpm/@supabase+realtime-js@2.11.10/node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
Critical dependency: the request of a dependency is an expression

v2.50.1-next.6 solved it for me. Would you release a new (intermediate) version back porting the fix?

Hey all, could you you please try out using v2.50.1-next.6 and let me know if that fixes your issue?

Thanks.

Works for me! I will do another test alter that day, but looks good so far! ❤️

Hey all, could you you please try out using v2.50.1-next.6 and let me know if that fixes your issue?

Thanks.

Same issue here, "@supabase/supabase-js": "^2.50.0" i get this error on project startup and realtime subscriptions are not firing at all.

../../node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
../../node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
../../node_modules/@supabase/realtime-js/dist/main/index.js
../../node_modules/@supabase/supabase-js/dist/module/index.js
./src/lib/supabase/admin.ts
./src/app/(server)/actions/admin-actions.ts

Tried also with 2.50.1-next.5, the warning goes away but the realtime subscriptions still do not work.

Downgrading to previous versions fixes the issue

I have the exact same thing and need to keep it at 2.49.9 for now

Facing the same issue here:

$ next dev -p 3000 ▲ Next.js 15.3.3

✓ Starting… ✓ Ready in 1292ms ✓ Compiled /middleware in 139ms (244 modules) ○ Compiling /[schema_name] … ⚠ ./node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js Critical dependency: the request of a dependency is an expression

Import trace for requested module: ./node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js ./node_modules/@supabase/realtime-js/dist/main/index.js ./node_modules/@supabase/supabase-js/dist/module/index.js ./node_modules/@supabase/ssr/dist/module/createBrowserClient.js ./node_modules/@supabase/ssr/dist/module/index.js ./utils/supabase/server.ts ./utils/auth.ts ./app/not-found.tsx ⚠ ./node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js Critical dependency: the request of a dependency is an expression

Import trace for requested module: ./node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js ./node_modules/@supabase/realtime-js/dist/main/index.js ./node_modules/@supabase/supabase-js/dist/module/index.js ./node_modules/@supabase/ssr/dist/module/createBrowserClient.js ./node_modules/@supabase/ssr/dist/module/index.js ./utils/supabase/server.ts ./utils/auth.ts ./app/not-found.tsx

I am also getting this same issue in 2.50.0. I have not seen any side-effects yet and it only appears as a warning.

  "scripts": {
    "dev": "next dev --turbopack",
    "dev:webpack": "next dev",
    "build": "next build",
    "start": "next start",
    ... other commands

  },

   "dependencies":{
     ...other libs
    "@supabase/supabase-js": "^2.49.10",
}

With Webpack

$ npm run dev:webpack

> app@0.1.0 dev:webpack
> next dev

✔ Console Ninja extension is connected to Next.js, see https://tinyurl.com/2vt8jxzw
   ▲ Next.js 15.3.3
   - Local:        http://localhost:3000
   - Network:      http://192.168.3.7:3000
   - Environments: .env.local, .env

 ✓ Starting...
 ✓ Ready in 3.7s
 ✓ Compiled /middleware in 301ms (119 modules)
 ○ Compiling /page/invoices ...
 ⚠ ./node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
./node_modules/@supabase/realtime-js/dist/main/index.js
./node_modules/@supabase/supabase-js/dist/module/index.js
./node_modules/@supabase/ssr/dist/module/createBrowserClient.js
./node_modules/@supabase/ssr/dist/module/index.js
./src/lib/supabase/server.ts

with Turbopack

$ npm run dev

> app@0.1.0 dev
> next dev --turbopack

✔ Console Ninja extension is connected to Next.js, see https://tinyurl.com/2vt8jxzw
   ▲ Next.js 15.3.3 (Turbopack)
   - Local:        http://localhost:3000
   - Network:      http://192.168.3.7:3000
   - Environments: .env.local, .env

 ✓ Starting...
 ✓ Compiled middleware in 263ms
 ✓ Ready in 3.3s
 ○ Compiling /page/invoices ...
 ✓ Compiled /page/invoices in 8.3s
 GET /page/invoices 200 in 9892ms
 ○ Compiling /_not-found/page ...
 ✓ Compiled /_not-found/page in 1771ms
 GET /.well-known/appspecific/com.chrome.devtools.json 404 in 2375ms
 ○ Compiling /api/auth/get-session-token ...

When I run with webpack with the newest version as of today June 5, 2025, I get that error, but when I run with turbopack I don’t get that error.

Then I looked in the code and noticed that it made a curious dynamic import:

            _fetch = (...args) => Promise.resolve(`${'@supabase/node-fetch'}`).then(s => __importStar(require(s))).then(({ default: fetch }) => fetch(...args));

Edit: it actually doesn’t break builds, it compiles with warnings

So true! I’ve updated the title. I quickly created this so I wouldn’t forget to do it