supabase icon indicating copy to clipboard operation
supabase copied to clipboard

Uncaught ReferenceError: exports is not defined

Open Psycarlo opened this issue 2 months ago • 6 comments

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)

  1. Create a project with nuxt and nuxt/supabase.
pnpm create nuxt@latest .

Nuxt: 4.2.2

pnpm dlx nuxi@latest module add supabase
  1. View the error in dev tools
Uncaught (in promise) ReferenceError: exports is not defined

Note: pnpm build and pnpm preview work without problems

Psycarlo avatar Dec 11 '25 18:12 Psycarlo

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.

andrew-mathieu avatar Dec 12 '25 01:12 andrew-mathieu

I tried with npm and fixed the issue. But moving away from pnpm is not an option for me.

Psycarlo avatar Dec 12 '25 17:12 Psycarlo

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",
      ],
    },
  },

nsina avatar Dec 13 '25 01:12 nsina

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", ], }, },

Seems to work, thank you!

andrew-mathieu avatar Dec 13 '25 01:12 andrew-mathieu

Does not work for me.

Psycarlo avatar Dec 13 '25 23:12 Psycarlo

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',
  },

Shooteger avatar Dec 14 '25 07:12 Shooteger

Also adding shamefullyHoist: true in pnpm-workspace.yaml solved it for me.

Psycarlo avatar Dec 14 '25 12:12 Psycarlo