Skip to content

Commit 666e773

Browse files
doc: fix wrong articles used to address modules
PR-URL: #57090 Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent f1b951f commit 666e773

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

doc/api/modules.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ This property is experimental and can change in the future. It should only be us
253253
by tools converting ES modules into CommonJS modules, following existing ecosystem
254254
conventions. Code authored directly in CommonJS should avoid depending on it.
255255

256-
When a ES Module contains both named exports and a default export, the result returned by `require()`
256+
When an ES Module contains both named exports and a default export, the result returned by `require()`
257257
is the module namespace object, which places the default export in the `.default` property, similar to
258258
the results returned by `import()`.
259259
To customize what should be returned by `require(esm)` directly, the ES Module can export the
@@ -373,7 +373,7 @@ LOAD_AS_FILE(X)
373373
1. MAYBE_DETECT_AND_LOAD(X.js)
374374
c. If the SCOPE/package.json contains "type" field,
375375
1. If the "type" field is "module", load X.js as an ECMAScript module. STOP.
376-
2. If the "type" field is "commonjs", load X.js as an CommonJS module. STOP.
376+
2. If the "type" field is "commonjs", load X.js as a CommonJS module. STOP.
377377
d. MAYBE_DETECT_AND_LOAD(X.js)
378378
3. If X.json is a file, load X.json to a JavaScript Object. STOP
379379
4. If X.node is a file, load X.node as binary addon. STOP
@@ -384,7 +384,7 @@ LOAD_INDEX(X)
384384
b. If no scope was found, load X/index.js as a CommonJS module. STOP.
385385
c. If the SCOPE/package.json contains "type" field,
386386
1. If the "type" field is "module", load X/index.js as an ECMAScript module. STOP.
387-
2. Else, load X/index.js as an CommonJS module. STOP.
387+
2. Else, load X/index.js as a CommonJS module. STOP.
388388
2. If X/index.json is a file, parse X/index.json to a JavaScript object. STOP
389389
3. If X/index.node is a file, load X/index.node as binary addon. STOP
390390

doc/changelogs/CHANGELOG_V22.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ Support for loading native ES modules using require() had been available on v20.
564564

565565
This feature is still experimental, and we are looking for user feedback to make more final tweaks before fully stabilizing it. For this reason, on v23.x, when the Node.js instance encounters a native ES module in require() for the first time, it will emit an experimental warning unless `require()` comes from a path that contains `node_modules`. If there happens to be any regressions caused by this feature, users can report it to the Node.js issue tracker. Meanwhile this feature can also be disabled using `--no-experimental-require-module` as a workaround.
566566

567-
With this feature enabled, Node.js will no longer throw `ERR_REQUIRE_ESM` if `require()` is used to load a ES module. It can, however, throw `ERR_REQUIRE_ASYNC_MODULE` if the ES module being loaded or its dependencies contain top-level `await`. When the ES module is loaded successfully by `require()`, the returned object will either be a ES module namespace object similar to what's returned by `import()`, or what gets exported as `"module.exports"` in the ES module.
567+
With this feature enabled, Node.js will no longer throw `ERR_REQUIRE_ESM` if `require()` is used to load an ES module. It can, however, throw `ERR_REQUIRE_ASYNC_MODULE` if the ES module being loaded or its dependencies contain top-level `await`. When the ES module is loaded successfully by `require()`, the returned object will either be an ES module namespace object similar to what's returned by `import()`, or what gets exported as `"module.exports"` in the ES module.
568568

569569
Users can check `process.features.require_module` to see whether `require(esm)` is enabled in the current Node.js instance. For packages, the `"module-sync"` exports condition can be used as a way to detect `require(esm)` support in the current Node.js instance and allow both `require()` and `import` to load the same native ES module. See [the documentation](https://nodejs.org/docs/latest/api/modules.html#loading-ecmascript-modules-using-require) for more details about this feature.
570570

0 commit comments

Comments
 (0)