Skip to content

Commit ff08094

Browse files
authored
doc: remove extensionless CJS exception for type:module packages
Remove the documented exception that extensionless files in type: "module" packages are recognized as CommonJS when included via require(). This exception conflicted with the ESM resolution specification which states that extensionless files within a package scope with an explicit type field follow the format of the type field. The behavior on main already matches the ESM spec since #61600, this change aligns the CJS documentation accordingly. Refs: #61600 Refs: #62083 PR-URL: #62176 Refs: #61600 Refs: #62083 Refs: #61971 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 43d5058 commit ff08094

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

doc/api/modules.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ Node.js has two module systems: CommonJS modules and [ECMAScript modules][].
7676

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

79-
* Files with a `.cjs` extension;
79+
* Files with a `.cjs` extension.
8080

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

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

93-
* Files with an extension that is not `.mjs`, `.cjs`, `.json`, `.node`, or `.js`
94-
(when the nearest parent `package.json` file contains a top-level field
95-
[`"type"`][] with a value of `"module"`, those files will be recognized as
96-
CommonJS modules only if they are being included via `require()`, not when
97-
used as the command-line entry point of the program).
94+
* Files with an extension that is not `.mjs`, `.cjs`, `.json`, `.node`, or `.js`,
95+
when the nearest parent `package.json` file contains a top-level field
96+
[`"type"`][] with a value of `"module"`.
9897

9998
See [Determining module system][] for more details.
10099

0 commit comments

Comments
 (0)