2.49.9 breaks application code on Vercel (error 500)
Bug report
Describe the bug
at (../../../../../node_modules/.pnpm/[email protected]/node_modules/ws/browser.js:4:8)
at (../../../../../node_modules/.pnpm/@[email protected]/node_modules/@supabase/realtime-js/src/RealtimeClient.ts:222:20)
at (../../../../../node_modules/.pnpm/@[email protected]/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)
Hi @wiesson thank you for reporting the issue, we're working on fix for it, would be great if you could try out the version "@supabase/supabase-js": "2.49.9-next.3" and confirm if that fixed it for you.
Thanks.
I just deployed a version with "@supabase/supabase-js": "2.49.9-next.3", but I have the same error.
Error: ws does not work in the browser. Browser clients must use the native WebSocket object
at (../../../../../node_modules/.pnpm/[email protected]/node_modules/ws/browser.js:4:8)
at (../../../../../node_modules/.pnpm/@[email protected]/node_modules/@supabase/realtime-js/src/RealtimeClient.ts:222:20)
at (../../../../../node_modules/.pnpm/@[email protected]/node_modules/@supabase/realtime-js/src/RealtimeChannel.ts:218:18)
It works with 2.49.8, so I'm not sure if I'm supposed to change sth
@wiesson can you check with the latest version of supabase-js?
Hey! Seeing this error now:
../../node_modules/.pnpm/@[email protected]/node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
Critical dependency: the request of a dependency is an expression
are you able to provide some example code so we can replica the issue?
also reopening this issue
Will try to create a repro when I get back home later. Here are some additional logs & details in the meantime:
../../node_modules/.pnpm/@[email protected]/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/.pnpm/@[email protected]/node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
../../node_modules/.pnpm/@[email protected]/node_modules/@supabase/realtime-js/dist/main/index.js
../../node_modules/.pnpm/@[email protected]/node_modules/@supabase/supabase-js/dist/module/index.js
../../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@supabase/ssr/dist/module/createBrowserClient.js
../../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@supabase/ssr/dist/module/index.js
./src/lib/supabase/server.ts
Actually now that I look at the import trace it looks like the ssr module is using createBrowserClient under the hood, even for the server client. Here's my supabase/server.ts (copied straight from the docs).
import 'server-only';
import { createServerClient } from '@supabase/ssr';
import type { Database } from 'common/types/database';
import { cookies } from 'next/headers';
export function createClient() {
const cookieStore = cookies();
return createServerClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return cookieStore.getAll();
},
setAll(cookiesToSet) {
try {
cookiesToSet.forEach(({ name, value, options }) => cookieStore.set(name, value, options));
} catch {
// The `setAll` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
},
);
}
OK so the repro is literally the official nextjs template: npx create-next-app -e with-supabase.
#1442 might also be related.
Error: ws does not work in the browser. Browser clients must use the native WebSocket object
at (../../../../../node_modules/.pnpm/[email protected]/node_modules/ws/browser.js:4:8)
at (../../../../../node_modules/.pnpm/@[email protected]/node_modules/@supabase/realtime-js/src/RealtimeClient.ts:222:20)
at (../../../../../node_modules/.pnpm/@[email protected]/node_modules/@supabase/realtime-js/src/RealtimeChannel.ts:218:18)
Still the same error, is 2.11.10 the correct version to test with?
Yeah, it's the latest version. Honestly, I kinda expected this issue to get more attention, considering it breaks builds...
Edit: it actually doesn't break builds, it compiles with warnings
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
@filipecabaco just wanted to ping you in case you didn't see the repro already
"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
> [email protected] 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
> [email protected] 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));
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 😓
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
}
}
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/@[email protected]/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/@[email protected]/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/@[email protected]/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/@[email protected]/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/@[email protected]/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/@[email protected]/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/@[email protected]/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/@[email protected]/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
I also have the Critical dependency: the request of a dependency is an expression warning since very recently.
Adding on that we're seeing Critical dependency: the request of a dependency is an expression with 2.50.0, and that it is causing some realtime subscriptions to fail to receive any payloads.
Revert to 2.49.8 has resolved the problem
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.
I am also getting these warnings after using 2.50.0. Not seeing any side effects, but it's annoying to see so many warnings each time it gets called. Please let us know once this is fixed.
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 😓
Sounds good! Let us know if there's anything we need to do/can do on our side