Repository navigation
fix: resolve the ESM build through the default export condition - #7132
overbalance merged 6 commits into
Conversation
Pull request dashboard statusMerged · refreshed 2026-09-29 17:41 UTC Status above doesn't look right?
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7132 +/- ##
=======================================
Coverage 95.04% 95.04%
=======================================
Files 383 383
Lines 13468 13468
Branches 3100 3100
=======================================
Hits 12801 12801
Misses 667 667 🚀 New features to boost your workflow:
|
|
Could we add a test where neither |
|
@JacksonWeber Added in 5801037: |
| } | ||
| } | ||
| if (pkg.exports && typeof pkg.exports === 'object') { | ||
| for (const [subpath, cond] of Object.entries(pkg.exports)) { |
There was a problem hiding this comment.
nit: IIUC, this won't handle an "exports" form like:
"exports": {
"import": "./index-module.js",
"require": "./index-require.cjs"
},but we don't have any of those and don't expect to, so this is a non-block nit.
Could throw in an assert that blows up if that surprise shows up, but I'm fine either way.
| for (const [subpath, cond] of Object.entries(pkg.exports)) { | |
| for (const [subpath, cond] of Object.entries(pkg.exports)) { | |
| assert(subpath.startsWith('.'), `${label} :: exports "${subpath}" isn't a subpath, this "exports" form isn't supported by this script"`); |
Would need the import of assert at the top, then.
There was a problem hiding this comment.
Good catch. Rather than assert, I normalized the shorthand the way Node does ({ ".": exports }) in a small subpathMap helper. collectEntries had the same assumption, so both now use it. Your example now fails with has no fallback without import/require. Fixed in f81c549.
…fault condition The exports map now uses the "require" and "default" conditions, as in open-telemetry#7132. The package.json file also drops the "module" field, as in open-telemetry#7130. Assisted-by: Claude Opus 5.5 Signed-off-by: Wolfgang Therrien <wolfgang@wolfgangcodes.com>
Summary
Every
exportsentry now listsrequirefirst and puts the ESM build underdefault, instead of underimport:With only
importandrequire, the map had no fallback. A resolver that activates neither condition (for example, a customconditionNameslist) failed with "No exports main defined". The Node.js docs recommend ending every condition object withdefault, and this change adds that fallback.This split out of the
#platformwork, which uses the samerequire/defaultshape for theimportsfield.Resolution changes
importorrequirefrom the import syntax (Node.js, TypeScript, webpack 5, esbuild, Rollup, Parcel, Vite, Jest and Metro 0.84+) resolve the same files as before.requirecomes first. One example is Metro before it started to assert only one condition per request, since its default was['require', 'import'].How Has This Been Tested?
npm run compilenpm run verify-pack: all 38 packages resolve. On npm 12 this needs thepack --jsonfix, which has its own PR.exportssubpath with neitherimportnorrequireactive, and fails if nothing resolves or the result differs from theimporttarget.npm run test:bundle: all 9 bundler tests pass (webpack 5, Next.js 15/16 edge, Jest jsdom, TypeScript legacy resolution, Metro, Expo).