Skip to content

fix(packaging): add exports map so default import works under Vite/Vitest#1655

Open
MatthewHarrigan wants to merge 1 commit into
auth0:masterfrom
MatthewHarrigan:fix/exports-map
Open

fix(packaging): add exports map so default import works under Vite/Vitest#1655
MatthewHarrigan wants to merge 1 commit into
auth0:masterfrom
MatthewHarrigan:fix/exports-map

Conversation

@MatthewHarrigan
Copy link
Copy Markdown

Fixes #1654.

Changes

Adds an exports field to package.json so each module environment resolves auth0-js to the correct bundle. No code changes; no dist/ rebuild; no build/test infrastructure changes.

"exports": {
  ".": {
    "import":  "./dist/auth0.min.esm.js",
    "require": "./dist/auth0.min.js",
    "default": "./dist/auth0.min.esm.js"
  },
  "./dist/*":        "./dist/*",
  "./build/*":       "./build/*",
  "./package.json":  "./package.json"
}

Why this works:

Honest scope

This PR fixes the ESM consumer path (the bug in #1654 — the one breaking the documented import). The pure-Node CJS require() path remains broken on v10 because "type": "module" causes Node to load .js files as ESM regardless of the require condition target, so the UMD bundle's exports.X = ... writes still have no effect. Fixing that properly requires renaming the UMD output to .cjs (or splitting the build), which is out of scope here. Filing as a separate concern if maintainers want.

Verified on a baseline of v10.0.0 master (pre-PR): require('auth0-js') already returns [Module: null prototype] {} — so this PR neither fixes nor regresses CJS.

References

Testing

All existing local CI gates green against this branch:

Gate Result
npm run lint clean
npm run build produces all 4 expected artifacts
npm test 658 passing
npm run test:es-check:es5 pass
npm run test:es-check:es2015:module pass

I didn't run npm run smoke:modern or the BrowserStack e2e tests — those need toolchain I don't have set up locally. Happy to add coverage if the reviewer suggests a specific gate.

Resolution probe (Node 22, ESM consumer)

Against the unmodified v10.0.0:

default import: undefined
namespace keys: []

Against this branch:

default import: { Authentication: [Function], Management: [Function], WebAuth: [Function], version: '10.0.0' }
default.Authentication: function
default.WebAuth: function
  • This change adds unit test coverage — N/A, packaging-only metadata change
  • This change adds integration test coverage — N/A, packaging-only metadata change

Checklist

…Vitest

Fixes auth0#1654.

v10.0.0 added `"type": "module"` to package.json but kept `main`
pointing at the UMD bundle (`dist/auth0.min.js`) without an `exports`
map. Bundlers that respect `"type": "module"` (Vite, Vitest, modern
esbuild) load the UMD file as ESM and find no top-level `export`
statements — so `import auth0 from 'auth0-js'` resolves to `undefined`,
breaking the documented `new auth0.WebAuth(...)` / `new auth0.Authentication(...)`
usage shown in the README.

This commit adds an `exports` map so each environment receives the
right bundle:

  - `import`  → `dist/auth0.min.esm.js` (real ESM exports)
  - `require` → `dist/auth0.min.js`     (UMD; Jest-style transformers
                                         handle the `exports.X = ...`
                                         writes correctly)
  - `default` → `dist/auth0.min.esm.js` (fallback)

`./dist/*` and `./build/*` wildcards preserve any deep-path imports
consumers may have adopted as workarounds. `./package.json` is exposed
explicitly for tools that read it.

Verified locally:

  - `npm run lint`                  clean
  - `npm run build`                 produces all 4 expected artifacts
  - `npm test`                      658 passing
  - `npm run test:es-check:es5`     pass
  - `npm run test:es-check:es2015:module`  pass
  - Resolution probe under Node 22:
      `import auth0 from 'auth0-js'`                       → object with `.Authentication`/`.WebAuth`
      `import auth0 from 'auth0-js/dist/auth0.min.esm.js'` → same (deep-path workaround preserved)
@MatthewHarrigan MatthewHarrigan requested a review from a team as a code owner May 20, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v10.0.0: "type": "module" + UMD main breaks default import under Vite/Vitest (import auth0 from 'auth0-js' yields undefined)

1 participant