Skip to content

Commit 412923c

Browse files
committed
doc: esm: recommend always including "type" field, per 2019-06-19 meeting
Reference: nodejs/modules#342 (comment)
1 parent 73a1b5e commit 412923c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

doc/api/esm.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ if the nearest parent `package.json` contains `"type": "module"`.
9797
import './startup.js'; // Loaded as ES module because of package.json
9898
```
9999

100+
It is recommended that package authors always include the `"type"` field, even
101+
in packages where it is unnecessary because all sources are CommonJS (and so
102+
therefore the default `"type": "commonjs"` is implied) or because there are no
103+
files ending in `.js` (for example, all files end in `.mjs` or `.cjs` or
104+
`.wasm`, etc.). Being explicit about the `type` of the package will future-proof
105+
the package in case Node.js’ default type ever changes, and it will also make
106+
things easier for build tools and loaders to determine how the files in the
107+
package should be interpreted.
108+
100109
### Package Scope and File Extensions
101110

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

0 commit comments

Comments
 (0)