@@ -51,12 +51,13 @@ along with a reference for the [`package.json`][] fields defined by Node.js.
5151## Determining module system
5252
5353Node.js will treat the following as [ ES modules] [ ] when passed to ` node ` as the
54- initial input, or when referenced by ` import ` statements within ES module code:
54+ initial input, or when referenced by ` import ` statements or ` import() `
55+ expressions:
5556
56- * Files ending in ` .mjs ` .
57+ * Files whose name ends in ` .mjs ` .
5758
58- * Files ending in ` .js ` when the nearest parent ` package.json ` file contains a
59- top-level [ ` "type" ` ] [ ] field with a value of ` "module" ` .
59+ * Files whose name ends in ` .js ` when the nearest parent ` package.json ` file
60+ contains a top-level [ ` "type" ` ] [ ] field with a value of ` "module" ` .
6061
6162* Strings passed in as an argument to ` --eval ` , or piped to ` node ` via ` STDIN ` ,
6263 with the flag ` --input-type=module ` .
@@ -67,12 +68,12 @@ field, or string input without the flag `--input-type`. This behavior is to
6768preserve backward compatibility. However, now that Node.js supports both
6869CommonJS and ES modules, it is best to be explicit whenever possible. Node.js
6970will treat the following as CommonJS when passed to ` node ` as the initial input,
70- or when referenced by ` import ` statements within ES module code :
71+ or when referenced by ` import ` statements or ` import() ` expressions :
7172
72- * Files ending in ` .cjs ` .
73+ * Files whose name ends in ` .cjs ` .
7374
74- * Files ending in ` .js ` when the nearest parent ` package.json ` file contains a
75- top-level field [ ` "type" ` ] [ ] with a value of ` "commonjs" ` .
75+ * Files whose name ends in ` .js ` when the nearest parent ` package.json ` file
76+ contains a top-level field [ ` "type" ` ] [ ] with a value of ` "commonjs" ` .
7677
7778* Strings passed in as an argument to ` --eval ` or ` --print ` , or piped to ` node `
7879 via ` STDIN ` , with the flag ` --input-type=commonjs ` .
@@ -83,6 +84,23 @@ future-proof the package in case the default type of Node.js ever changes, and
8384it will also make things easier for build tools and loaders to determine how the
8485files in the package should be interpreted.
8586
87+ Node.js will refuse to load the following when passed to ` node ` as the
88+ initial input and the nearest parent ` package.json ` file contains a top-level
89+ [ ` "type" ` ] [ ] field with a value of ` "module" ` :
90+
91+ * Files whose name doesn't end in ` .js ` , ` .mjs ` , ` .cjs ` , or ` .wasm ` .
92+
93+ Passing to ` node ` as the initial input when the nearest parent ` package.json `
94+ file contains a top-level [ ` "type" ` ] [ ] field with a value of ` "commonjs" ` , or
95+ when referenced by ` require() ` calls:
96+
97+ * Files whose name ends in ` .node ` are interpreted as
98+ compiled addon modules loaded with ` process.dlopen() ` .
99+
100+ * Files whose name ends in ` .json ` are parsed as JSON text files.
101+
102+ * Any other files will be treated as a [ CommonJS] [ ] module.
103+
86104### ` package.json ` and file extensions
87105
88106Within a package, the [ ` package.json ` ] [ ] [ ` "type" ` ] [ ] field defines how
0 commit comments