fix(packaging): add exports map so default import works under Vite/Vitest#1655
Open
MatthewHarrigan wants to merge 1 commit into
Open
fix(packaging): add exports map so default import works under Vite/Vitest#1655MatthewHarrigan wants to merge 1 commit into
exports map so default import works under Vite/Vitest#1655MatthewHarrigan wants to merge 1 commit into
Conversation
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1654.
Changes
Adds an
exportsfield topackage.jsonso each module environment resolvesauth0-jsto the correct bundle. No code changes; nodist/rebuild; no build/test infrastructure changes.Why this works:
importcondition → ESM bundle. Fixes the bug reported in v10.0.0:"type": "module"+ UMDmainbreaks default import under Vite/Vitest (import auth0 from 'auth0-js'yieldsundefined) #1654: Vite/Vitest (and any modern bundler that respects"type": "module") were resolving the package to the UMDmain, loading it as ESM, finding no top-levelexportstatements, and handing consumersundefinedfor the default import. Routingimportdirectly at the ESM bundle restores the documentedimport auth0 from 'auth0-js'usage.requirecondition → UMD bundle. Jest-style transformers that readexportswill pick up the UMD file and execute it as CJS, whereexports.X = ...writes work correctly.defaultfallback → ESM bundle for any environment that doesn't match the above conditions../dist/*and./build/*wildcards preserve deep-path imports (auth0-js/dist/auth0.min.esm.jsetc.) that some consumers have adopted as a workaround for v10.0.0:"type": "module"+ UMDmainbreaks default import under Vite/Vitest (import auth0 from 'auth0-js'yieldsundefined) #1654. Once this lands the workaround is unnecessary, but keeping the wildcards avoids breaking anyone who's still on the workaround../package.jsonis exposed because some tools (TypeScript, bundlers) read it.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.jsfiles as ESM regardless of therequirecondition target, so the UMD bundle'sexports.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
"type": "module"+ UMDmainbreaks default import under Vite/Vitest (import auth0 from 'auth0-js'yieldsundefined) #1654import auth0 from 'auth0-js'thennew auth0.WebAuth({...})— the exact pattern broken by v10 packaging.Testing
All existing local CI gates green against this branch:
npm run lintnpm run buildnpm testnpm run test:es-check:es5npm run test:es-check:es2015:moduleI didn't run
npm run smoke:modernor 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:
Against this branch:
Checklist