Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
doc: fix duplicated wording in modules.md
  • Loading branch information
mcollina committed Mar 22, 2026
commit 9342855e42c03d8f4e7e60a446c2bb1a08aedfda
33 changes: 6 additions & 27 deletions doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ Node.js has two module systems: CommonJS modules and [ECMAScript modules][].

By default, Node.js will treat the following as CommonJS modules:

* Files with a `.cjs` extension;
* Files with a `.cjs` extension.

* Files with a `.js` extension when the nearest parent `package.json` file
contains a top-level field [`"type"`][] with a value of `"commonjs"`.
* Files with a `.js` extension or without an extension, when the nearest parent
`package.json` file contains a top-level field [`"type"`][] with a value of
`"commonjs"`.

* Files with a `.js` extension or without an extension, when the nearest parent
`package.json` file doesn't contain a top-level field [`"type"`][] or there is
Expand All @@ -90,31 +91,9 @@ By default, Node.js will treat the following as CommonJS modules:
tools and loaders to determine how the files in the package should be
interpreted.

* Files with an extension that is not `.mjs`, `.cjs`, `.json`, `.node`, or `.js`
(when the nearest parent `package.json` file contains a top-level field
[`"type"`][] with a value of `"module"`, those files will not be recognized as
By default, Node.js will treat the following as CommonJS modules:

* Files with a `.cjs` extension.

* Files with a `.js` extension or without an extension, when the nearest parent
`package.json` file contains a top-level field [`"type"`][] with a value of
`"commonjs"`.

* Files with a `.js` extension or without an extension, when the nearest parent
`package.json` file doesn't contain a top-level field [`"type"`][] or there is
no `package.json` in any parent folder; unless the file contains syntax that
errors unless it is evaluated as an ES module. Package authors should include
the [`"type"`][] field, even in packages where all sources are CommonJS. Being
explicit about the `type` of the package will make things easier for build
tools and loaders to determine how the files in the package should be
interpreted.

* Files with an extension that is not `.mjs`, `.cjs`, `.json`, `.node`, or `.js`,
when the nearest parent `package.json` file contains a top-level field
[`"type"`][] with a value of `"module"`.

See [Determining module system][] for more details.
Comment thread
GeoffreyBooth marked this conversation as resolved.
when the nearest parent `package.json` file contains a top-level field
[`"type"`][] with a value of `"module"`.
Comment thread
mcollina marked this conversation as resolved.

Calling `require()` always use the CommonJS module loader. Calling `import()`
always use the ECMAScript module loader.
Expand Down
Loading