-
Notifications
You must be signed in to change notification settings - Fork 541
Description
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.
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-jsso 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.1Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Supabase JS Library issue and not an issue with the Supabase platform. If it's a Supabase platform related bug, it should likely be reported to supabase/supabase instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.