From fccd01ba4a873dafb68091b7e1b75a029801c432 Mon Sep 17 00:00:00 2001 From: Ronald J Kimball Date: Wed, 1 May 2019 08:27:27 -0500 Subject: [PATCH 1/3] doc: fix explanation of package.json "type" field Remove erroneous reference to files with `.mjs` extension, which are not affected by the package.json "type" field. --- doc/api/esm.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 939965842833d8..463650ab3d439c 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -59,9 +59,9 @@ or when referenced by `import` statements within ES module code: ### `package.json` `"type"` field -Files ending with `.js` or `.mjs`, or lacking any extension, -will be loaded as ES modules when the nearest parent `package.json` file -contains a top-level field `"type"` with a value of `"module"`. +Files ending with `.js` or lacking any extension will be loaded as ES modules +when the nearest parent `package.json` file contains a top-level field `"type"` +with a value of `"module"`. The nearest parent `package.json` is defined as the first `package.json` found when searching in the current folder, that folder’s parent, and so on up From 1d6349746945f535570423555f612538bbcc5260 Mon Sep 17 00:00:00 2001 From: Ronald J Kimball Date: Tue, 31 Dec 2019 09:05:20 -0600 Subject: [PATCH 2/3] doc: further clarify package.json "type" field Added sentence about the type field not affecting .mjs and .cjs files. --- doc/api/esm.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/api/esm.md b/doc/api/esm.md index 463650ab3d439c..cbe8336ed8103a 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -101,6 +101,9 @@ future-proof the package in case the default type of Node.js ever changes, and it will also make things easier for build tools and loaders to determine how the files in the package should be interpreted. +Regardless of the value of the `"type"` field, `.mjs` files are always treated +as ES modules and `.cjs` files are always treated as CommonJS modules. + ### Package Scope and File Extensions A folder containing a `package.json` file, and all subfolders below that From 011fe0618e77f37870732c54d57674df40aaa1d7 Mon Sep 17 00:00:00 2001 From: Ronald J Kimball Date: Thu, 2 Jan 2020 12:43:13 -0600 Subject: [PATCH 3/3] doc: change "CommonJS modules" to "CommonJS" Co-Authored-By: Geoffrey Booth --- doc/api/esm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index cbe8336ed8103a..897fadb09ead9e 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -102,7 +102,7 @@ it will also make things easier for build tools and loaders to determine how the files in the package should be interpreted. Regardless of the value of the `"type"` field, `.mjs` files are always treated -as ES modules and `.cjs` files are always treated as CommonJS modules. +as ES modules and `.cjs` files are always treated as CommonJS. ### Package Scope and File Extensions