Skip to content

Commit 39dbc10

Browse files
tamiastargos
authored andcommitted
doc: improve explanation of package.json "type" field
Regardless of the value of the `"type"` field, `.mjs` files are always treated as ES modules and `.cjs` files are always treated as CommonJS. PR-URL: #27516 Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 7858d65 commit 39dbc10

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

doc/api/esm.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ or when referenced by `import` statements within ES module code:
6262

6363
### `package.json` `"type"` field
6464

65-
Files ending with `.js` or `.mjs`, or lacking any extension,
66-
will be loaded as ES modules when the nearest parent `package.json` file
67-
contains a top-level field `"type"` with a value of `"module"`.
65+
Files ending with `.js` or lacking any extension will be loaded as ES modules
66+
when the nearest parent `package.json` file contains a top-level field `"type"`
67+
with a value of `"module"`.
6868

6969
The nearest parent `package.json` is defined as the first `package.json` found
7070
when searching in the current folder, that folder’s parent, and so on up
@@ -104,6 +104,9 @@ future-proof the package in case the default type of Node.js ever changes, and
104104
it will also make things easier for build tools and loaders to determine how the
105105
files in the package should be interpreted.
106106

107+
Regardless of the value of the `"type"` field, `.mjs` files are always treated
108+
as ES modules and `.cjs` files are always treated as CommonJS.
109+
107110
### Package Scope and File Extensions
108111

109112
A folder containing a `package.json` file, and all subfolders below that

0 commit comments

Comments
 (0)