Skip to content

Commit

Permalink
doc: esm: recommend always including "type" field, per 2019-06-19 mee…
Browse files Browse the repository at this point in the history
…ting

Reference: nodejs/modules#342 (comment)
  • Loading branch information
GeoffreyBooth committed Sep 9, 2019
1 parent baa3e50 commit 0f1286a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ if the nearest parent `package.json` contains `"type": "module"`.
import './startup.js'; // Loaded as ES module because of package.json
```

It is recommended that package authors always include the `"type"` field, even
in packages where it is unnecessary because all sources are CommonJS (and so
therefore the default `"type": "commonjs"` is implied) or because there are no
files ending in `.js` (for example, all files end in `.mjs` or `.cjs` or
`.wasm`, etc.). Being explicit about the `type` of the package will future-proof
the package in case Node.js’ default type 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.

### Package Scope and File Extensions

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

0 comments on commit 0f1286a

Please sign in to comment.