From deb1a591f54e044174a8c3f53648eec25a40f5ca Mon Sep 17 00:00:00 2001 From: Ronald J Kimball Date: Wed, 1 May 2019 08:27:27 -0500 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/27516 Reviewed-By: Bradley Farias Reviewed-By: Rich Trott Reviewed-By: Ruben Bridgewater --- doc/api/esm.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 5ef8a616aa209d..0013e82fa3dfa2 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -62,9 +62,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 @@ -104,6 +104,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. + ### Package Scope and File Extensions A folder containing a `package.json` file, and all subfolders below that