From 7e108d3a2268db0ca72830492678ea1ae4d44d3c Mon Sep 17 00:00:00 2001 From: Matthew Harrigan Date: Wed, 24 Jun 2026 13:24:56 +0100 Subject: [PATCH] fix(packaging): add `exports` map so default import works under Vite/Vitest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #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) --- package.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/package.json b/package.json index 564cd08a..67efab64 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,16 @@ "type": "module", "module": "dist/auth0.min.esm.js", "main": "dist/auth0.min.js", + "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" + }, "files": [ "src", "plugins",