Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 39dbc10

Browse filesBrowse 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 <bradley.meck@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 7858d65 commit 39dbc10
Copy full SHA for 39dbc10

File tree

Expand file treeCollapse file tree

1 file changed

+6
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-3
lines changed
Open diff view settings
Collapse file

‎doc/api/esm.md‎

Copy file name to clipboardExpand all lines: doc/api/esm.md
+6-3Lines changed: 6 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.