This release introduces a "module-sync" exports condition that's enabled whenrequire(esm) is enabled, so packages can supply a synchronous ES module to theNode.js module loader, no matter if it's being required or imported. This issimilar to the "module" condition that bundlers have been using to supportrequire(esm) in Node.js, and allows dual-package authors to opt into ESM-firstonly on newer versions of Node.js that supports require(esm) to avoid thedual-package hazard.
{ "type": "module", "exports": {"node": { // On new version of Node.js, both require() and import get // the ESM version "module-sync": "./index.js", // On older version of Node.js, where "module-sync" and require(esm) are // not supported, use the CJS version to avoid dual-package hazard. // When package authors think it's time to drop support for older versions of // Node.js, they can remove the exports conditions and just use "main": "index.js". "default": "./dist/index.cjs"},// On any other environment, use the ESM version."default": "./index.js" }}Or if the package is only meant to be run on Node.js and wants to fallback toCJS on older versions that don't have require(esm):
{ "type": "module", "exports": {// On new version of Node.js, both require() and import get the ESM version"module-sync": "./index.js",// On older version of Node.js, where "module-sync" and require(esm) are// not supported, use the CJS version to avoid dual-package hazard.// When package authors think it's time to drop support for older versions of// Node.js, they can remove the exports conditions and just use "main": "index.js"."default": "./dist/index.cjs" }}For package authors: this only serves as a feature-detection mechanism forpackages that wish to support both CJS and ESM users during the period when someactive Node.js LTS versions support require(esm) while some older ones don't.When all active Node.js LTS lines support require(esm), packages can simplifytheir distributions by bumping the major version, dropping their CJS exports,and removing the module-sync exports condition (with only main or defaulttargetting the ESM exports). If the package needs to support both bundlers andbeing run unbundled on Node.js during the transition period, use bothmodule-sync and module and point them to the same ESM file. If the packagealready doesn't want to support older versions of Node.js that doesn't supportrequire(esm), don't use this export condition.
For bundlers/tools: they should avoid implementing this stop-gap condition.Most existing bundlers implement the de-facto bundler standardmoduleexports condition, and that should be enough to support users who want to bundleESM from CJS consumers. Users who want both bundlers and Node.js to recognizethe ESM exports can use both module/module-sync conditions during thetransition period, and can drop module-sync+module when they no longer needto support older versions of Node.js. If tools do want to support thiscondition, it's recommended to make the resolution rules in the graph pointed bythis condition match the Node.js native ESM rules to avoid divergence.
We ended up implementing a condition with a different name instead of reusing"module", because existing code in the ecosystem using the "module"condition sometimes also expect the module resolution for these ESM files towork in CJS style, which is supported by bundlers, but the native Node.js loaderhas intentionally made ESM resolution different from CJS resolution (e.g.forbidding import './noext' or import './directory'), so it would bebreaking to implement a "module" condition without implementing the forbiddenESM resolution rules. For now, this just implements a new condition assemver-minor so it can be backported to older LTS.
Contributed by Joyee Cheung in #54648.
node --run is now stableThis CLI flag runs a specified command from a package.json's "scripts" object.
For the following package.json:
{ "scripts": {"test": "node --test-reporter junit --test ./test" }}You can run node --run test and that would start the test suite.
Contributed by Yagiz Nizipli in #53763.
Other notable changes[f0b441230a] - (SEMVER-MINOR) crypto: add KeyObject.prototype.toCryptoKey (Filip Skokan) #55262[349d2ed07b] - (SEMVER-MINOR) crypto: add Date fields for validTo and validFrom (Andrew Moon) #54159[bebc95ed58] - doc: add abmusse to collaborators (Abdirahim Musse) #55086[914db60159] - (SEMVER-MINOR) http2: expose nghttp2_option_set_stream_reset_rate_limit as an option (Maël Nison) #54875[f7c3b03759] - (SEMVER-MINOR) lib: propagate aborted state to dependent signals before firing events (jazelly) #54826[32261fc98a] - (SEMVER-MINOR) module: support loading entrypoint as url (RedYetiDev) #54933[06957ff355] - (SEMVER-MINOR) module: implement flushCompileCache() (Joyee Cheung) #54971[2dcf70c347] - (SEMVER-MINOR) module: throw when invalid argument is passed to enableCompileCache() (Joyee Cheung) #54971[f9b19d7c44] - (SEMVER-MINOR) module: write compile cache to temporary file and then rename it (Joyee Cheung) #54971[e95163b170] - (SEMVER-MINOR) process: add process.features.require_module (Joyee Cheung) #55241[4050f68e5d] - (SEMVER-MINOR) process: add process.features.typescript (Aviv Keller) #54295[86f7cb802d] - (SEMVER-MINOR) test_runner: support custom arguments in run() (Aviv Keller) #55126[b62f2f8259] - (SEMVER-MINOR) test_runner: add 'test:summary' event (Colin Ihrig) #54851[d7c708aec5] - (SEMVER-MINOR) test_runner: add support for coverage via run() (Chemi Atlow) #53937[5fda4a1498] - (SEMVER-MINOR) worker: add markAsUncloneable api (Jason Zhang) #55234Commits[e3619510c8] - assert: show the diff when deep comparing data with a custom message (Giovanni) #54759[39c7a9e70c] - benchmark: adjust config for deepEqual object (Rafael Gonzaga) #55254[263526d5d0] - benchmark: rewrite detect-esm-syntax benchmark (Joyee Cheung) #55238[cd0795fb00] - benchmark: add no-warnings to process.has bench (Rafael Gonzaga) #55159[4352d9cc31] - benchmark: create benchmark for typescript (Marco Ippolito) #54904[452bc9b48d] - benchmark: add webstorage benchmark (jakecastelli) #55040[d4d5ba3a9b] - benchmark: include ascii to fs/readfile (Rafael Gonzaga) #54988[23b628db65] - benchmark: add dotenv benchmark (Aviv Keller) #54278[b1ebb0d8ca] - buffer: coerce extrema to int in blob.slice (Antoine du Hamel) #55141[3a6e72483f] - buffer: extract Blob's .arrayBuffer() & webidl changes (Matthew Aitken) #53372[d109f1c4ff] - buffer: use simdutf convert_latin1_to_utf8_safe (Robert Nagy) #54798[77f8a3f9c2] - ...