Repository navigation
fix: make the Node.js ESM entry work on Node.js 14.0 - #191
Merged
Merged
Conversation
|
Coverage after merging fix/node-14-esm-entry into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This was referenced Oct 7, 2026
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.
Part of #168.
Summary
The v2 pre-release review (R3) found that
import 'mutative'fails on Node.js 14.0 to 14.12, althoughenginesdeclares>=14.0. #182 made thenodeimport condition resolvedist/index.mjs, which re-exports the CJS entry by name,export { apply, create, … } from './index.js'. Node.js detects the names that a CommonJS module exports only since 14.13.0, so earlier versions reject the entry:require('mutative')works on every version, and npm 1.3.0, whoseimportresolved the ESM bundle, works on 14.0, with two instances. This PR keepsenginesat>=14.0and makes the entry work there, without changing its exports or the one instance thatimportandrequireshare.Changes, one commit per item
fix: make the Node.js ESM entry work on Node.js 14.0: the entry takes the exports object of the CJS entry as its default import and exports its functions by name. A default import of a CommonJS module works on every Node.js version with ES modules, and it is the same CJS instance thatrequirereturns.scripts/write-package-entries.mjsfails if the CJS bundle sets__esModule, because bundlers that resolve this entry and follow that convention would then importexports.default; the bundle sets it neither now nor before.test: check the packed package on the oldest Node.js version that engines allows:scripts/check-minimum-node.mjsinstalls the packed tarball with that version's npm and, in development and production, loads the CJS entry withrequireand the Node.js ESM entry with static and dynamicimport, checks that both expose the same functions of one instance, and runs a runtime test of objects, native array methods, Map and Set drafts, auto-freeze, patches, strict mode, marks, manual finalization and async recipes. It refuses to run on any version other than the floor ofengines, so the CI job has to follow a change ofengines. A newminimum-nodejob in the Node CI workflow builds and packs with Node.js 24 and runs the script with Node.js 14.0.0. The script only uses what Node.js 14.0 provides: nonode:specifiers,assert/strictor top-levelawait.test: bundle the Node.js ESM entry for Node.js in the package checks:pnpm test:packagealso bundles the package with esbuild for Node.js, which resolves thenodecondition and so this entry, and runs the bundle with all exports, in development and production.docs: describe the Node.js ESM entry and the minimum Node.js check: BUILDING.md.Verification
The packed tarballs of
mainand of this PR, installed in a consumer and run on Node.js binaries from nodejs.org (x64 under Rosetta for 14.x), in development and production, with named, namespace and dynamicimport:main:importimportrequireimportandrequireshare one instanceSyntaxErrorscripts/check-minimum-node.mjspasses on Node.js 14.0.0 with this PR, fails with theSyntaxErrorabove on the tarball ofmain, and refuses to run on 14.13.0 and 24.16.test:package, lint and the format check. Of the 76 files in the tarball, onlydist/index.mjschanges, sopnpm sizeand the size baseline are unaffected.Not covered
Deep imports such as
mutative/dist/mutative.cjs.production.min.jsresolve through the"./*"subpath pattern inexports, which Node.js supports since 14.13.0. On 14.0 to 14.12 they fail withERR_PACKAGE_PATH_NOT_EXPORTED, as they did with 1.3.0; the docs do not describe such imports.