Uncaught ReferenceError: exports is not defined
Version
@nuxtjs/supabase: 1.6.2 pnpm: 10.23.0 node: 22.20
Steps to reproduce
https://stackblitz.com/edit/nuxt-starter-ij2jcsq3 (Add .env vars add run)
- Create a project with nuxt and nuxt/supabase.
pnpm create nuxt@latest .
Nuxt: 4.2.2
pnpm dlx nuxi@latest module add supabase
- View the error in dev tools
Uncaught (in promise) ReferenceError: exports is not defined
Note: pnpm build and pnpm preview work without problems
Same here.
Edit: After trying with npm install instead of pnpm install, it seems to solve this. The issue seems to be at this level.
I tried with npm and fixed the issue. But moving away from pnpm is not an option for me.
The latest @supabase/supabase-js has a dual CommonJS/ESM distribution and Vite seems to be failing the pre-bundling of Supabase pakages during dev (hence causing the browser to load the CommonJS version [index.js with exports] instead of the ESM version.)
To resolve the issue, I added the following in nuxt.config.js:
vite: {
optimizeDeps: {
include: [
"@supabase/supabase-js",
"@supabase/postgrest-js",
"@supabase/auth-js",
"@supabase/realtime-js",
"@supabase/storage-js",
"@supabase/functions-js",
],
},
},
The latest
@supabase/supabase-jshas a dual CommonJS/ESM distribution and Vite seems to be failing the pre-bundling of Supabase pakages during dev (hence causing the browser to load the CommonJS version [index.js with exports] instead of the ESM version.)To resolve the issue, I added the following in
nuxt.config.js:vite: { optimizeDeps: { include: [ "@supabase/supabase-js", "@supabase/postgrest-js", "@supabase/auth-js", "@supabase/realtime-js", "@supabase/storage-js", "@supabase/functions-js", ], }, },
Seems to work, thank you!
Does not work for me.
This here works for me to resolve the export issues (both spa and ssr:true) on Nuxt v4.2.2 (most current as of writing):
vite: {
optimizeDeps: {
include: ['@supabase/postgrest-js', '@supabase/supabase-js']
}
},
nitro: {
externals: {
inline: ['@supabase/supabase-js']
}
},
supabase: {
redirect: false,
types: '../shared/types/database.types.ts',
},
Also adding shamefullyHoist: true in pnpm-workspace.yaml solved it for me.