Skip to content

Vite dev regression after #1914: exports is not defined from CJS wrapper in @supabase/supabase-js@^2.86.0 #1942

@mercmobily

Description

@mercmobily

Describe the bug

Thank you for the terrific work.

I believe there is a regression after #1914: the new ESM wrapper (dist/esm/wrapper.mjs) imports the CJS build (dist/main/index.js). When served raw (no prebundle), the browser executes the CJS file and crashes with ReferenceError: exports is not defined.

Right now the wrapper means browsers hit the CJS main whenever it isn't pre-bundled. That's probably a regression for direct ESM use, and a little surprising in a minor bump. Maybe a browser-safe export (or conditional export) would keep the Nuxt fix while avoiding manual optimizeDeps tweaks across tools.

So... I guess the request is: please ship a browser-safe ESM build or a conditional export for browsers, so direct ESM imports don’t land on the CJS main and crash.

@welchmd

Library affected

supabase-js

Reproduction

No response

Steps to reproduce

Minimal repro (no other deps):

mkdir supa-raw && cd supa-raw
npm init -y
npm install @supabase/[email protected] serve
cat > index.html <<'EOF'
<!DOCTYPE html>
<html>
  <body>
    <script type="module">
      import { createClient } from "./node_modules/@supabase/supabase-js/dist/esm/wrapper.mjs";
      console.log(createClient);
    </script>
  </body>
</html>
EOF
npx serve .

Open http://localhost:3000 (or whatever serve prints). In the browser console you'll see:

Uncaught ReferenceError: exports is not defined
    at http://localhost:3000/node_modules/@supabase/supabase-js/dist/main/index.js:19:23

Expected: the published ESM entry should work in the browser without requiring a prebundle.

Workarounds:

  • Force bundlers (Vite, etc.) to pre-bundle @supabase/supabase-js so the CJS is wrapped, or
  • Pin to <=2.79.0 (before the wrapper/exports change).

System Info

System:
    OS: Linux 6.14 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Memory: 3.64 GB / 15.28 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 20.19.0 - /home/merc/.nvm/versions/node/v20.19.0/bin/node
    Yarn: 1.22.22 - /home/merc/.nvm/versions/node/v20.19.0/bin/yarn
    npm: 11.6.2 - /home/merc/.nvm/versions/node/v20.19.0/bin/npm
    pnpm: 10.25.0 - /home/merc/.nvm/versions/node/v20.19.0/bin/pnpm
  Browsers:
    Chrome: 143.0.7499.40
  npmPackages:
    @supabase/supabase-js: ^2.87.1 => 2.87.1

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsupabase-jsRelated to the supabase-js library.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions