Skip to content

Conversation

@mandarini
Copy link
Contributor

@mandarini mandarini commented Dec 16, 2025

Summary

This PR migrates the build system for postgrest-js, storage-js, and supabase-js from the legacy tsc + wrapper.mjs approach to tsdown, fixing critical ESM module resolution issues that caused production outages for users.

Background

I initially planned to use tsup, but discovered it's no longer actively maintained. The tsup repository itself recommends using tsdown (its actively maintained successor built on Rolldown).

Issues Fixed

Issue Description Root Cause
#1955 AuthClient is null - jsdelivr CDN imports broken wrapper.mjs incompatible with jsdelivr's /+esm transform
#1942 exports is not defined - Vite dev regression wrapper.mjs imports CJS, crashes in browser ESM context
#1880 ERR_MODULE_NOT_FOUND - Nuxt environment broken Missing .js extensions in ESM imports

All three issues stem from PR #1914 which introduced wrapper.mjs as a workaround. This PR properly fixes the underlying issue.

What Changed

Build Output Structure

Before:

  dist/
  ├── main/index.js          # CJS
  ├── module/index.js        # ESM (missing extensions)
  ├── esm/wrapper.mjs        # ESM wrapper → imports CJS (broken)
  └── umd/supabase.js        # UMD (webpack)

After:

  dist/
  ├── index.cjs              # CJS
  ├── index.mjs              # ESM (proper, self-contained)
  ├── index.d.cts            # CJS types
  ├── index.d.mts            # ESM types
  └── umd/supabase.js        # IIFE (tsdown)

Package Exports

Before:

  {
    "main": "dist/main/index.js",
    "module": "dist/esm/wrapper.mjs",
    "types": "dist/module/index.d.ts",
    "exports": {
      ".": {
        "types": "./dist/module/index.d.ts",
        "import": "./dist/esm/wrapper.mjs",
        "require": "./dist/main/index.js"
      }
    }
  }

After:

  {
    "main": "dist/index.cjs",
    "module": "dist/index.mjs",
    "types": "dist/index.d.cts",
    "exports": {
      ".": {
        "import": {
          "types": "./dist/index.d.mts",
          "default": "./dist/index.mjs"
        },
        "require": {
          "types": "./dist/index.d.cts",
          "default": "./dist/index.cjs"
        }
      },
      "./dist/*": "./dist/*",
      "./package.json": "./package.json"
    }
  }

Files Changed

Removed (no longer needed)

  • wrapper.mjs files (postgrest-js, supabase-js)
  • scripts/copy-wrapper.cjs files
  • scripts/fix-esm-extensions.cjs
  • webpack.config.js files (storage-js, supabase-js)
  • tsconfig.module.json files

Added

  • tsdown.config.ts for postgrest-js, storage-js, supabase-js
  • test/module-resolution.test.mjs - ESM import tests
  • test/module-resolution.test.cjs - CJS require tests
  • Module resolution CI job with attw validation

New Tests

To prevent regression, this PR adds comprehensive module resolution tests:

Test Purpose
test:exports Validates package exports with attw
test:esm Tests ESM imports work, explicitly checks AuthClient is not null
test:cjs Tests CJS requires work
UMD test (extended) Verifies all clients (auth, storage, functions, postgrest, realtime) are bundled

CI now runs a dedicated module-resolution job that validates:

  • Package exports work for node10, node16-cjs, node16-esm, and bundler resolution
  • ESM imports resolve correctly with all clients accessible
  • CJS requires work correctly

Backward Compatibility

  • ./dist/* wildcard export maintained for deep imports
  • UMD bundle path unchanged (dist/umd/supabase.js)
  • All public APIs unchanged

Related:

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 16, 2025

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@1961

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@1961

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@1961

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@1961

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@1961

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@1961

commit: 97872e7

@coveralls
Copy link

coveralls commented Dec 16, 2025

Coverage Status

coverage: 80.896% (-0.5%) from 81.37%
when pulling 97872e7 on feat/use-tsup
into f346169 on master.

@mandarini mandarini changed the title feat(repo): use tsup feat(repo): use tsdown Dec 16, 2025
@mandarini mandarini linked an issue Dec 16, 2025 that may be closed by this pull request
7 tasks
@mandarini mandarini changed the title feat(repo): use tsdown feat(repo): migrate build system to tsdown for proper ESM/CJS support Dec 16, 2025
@mandarini mandarini marked this pull request as ready for review December 16, 2025 15:55
@mandarini mandarini requested review from a team as code owners December 16, 2025 15:55
@mandarini mandarini merged commit 6c9bbdf into master Dec 16, 2025
31 of 32 checks passed
@mandarini mandarini deleted the feat/use-tsup branch December 16, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Module import/export mismatch

4 participants