fix(packaging): add exports map so default import works under Vite/Vitest#1655
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#1655Conversation
|
Hi @amitsingh05667 - I've updated the branch |
|
Hi @amitsingh05667 - is it possible to take another look at this if you have time? |
|
Hi @MatthewHarrigan, apologies for the late response. |
|
@MatthewHarrigan I think there is one commit that doesn't have a verified signature. Could you please sign all the commits and re push them. |
9b970cd to
f7bbe54
Compare
|
Hi @cschetan77 - I have tidied up the commits - please can you review |
|
Thanks @MatthewHarrigan , Could you rebase your branch as well. |
6622bb8 to
c99657f
Compare
…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)
c99657f to
7e108d3
Compare
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