GeezerVison is showing github.com — doc: improve explanation of package.json "type" field · nodejs/node@39dbc10
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
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 number | Diff line number | Diff line change |
|---|
@@ -62,9 +62,9 @@ or when referenced by `import` statements within ES module code: |
62 | 62 |
|
63 | 63 | ### `package.json` `"type"` field |
64 | 64 |
|
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"`. |
68 | 68 |
|
69 | 69 | The nearest parent `package.json` is defined as the first `package.json` found |
70 | 70 | 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 |
104 | 104 | it will also make things easier for build tools and loaders to determine how the |
105 | 105 | files in the package should be interpreted. |
106 | 106 |
|
| 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 | + |
107 | 110 | ### Package Scope and File Extensions |
108 | 111 |
|
109 | 112 | A folder containing a `package.json` file, and all subfolders below that |
|