Skip to content

Commit d3a8088

Browse files
tamiasBridgeAR
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 1b720aa commit d3a8088

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
@@ -59,9 +59,9 @@ or when referenced by `import` statements within ES module code:
5959

6060
### `package.json` `"type"` field
6161

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

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

104+
Regardless of the value of the `"type"` field, `.mjs` files are always treated
105+
as ES modules and `.cjs` files are always treated as CommonJS.
106+
104107
### Package Scope and File Extensions
105108

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

0 commit comments

Comments
 (0)