diff options
author | Guy Bedford <guybedford@gmail.com> | 2020-05-14 14:56:10 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 14:56:10 -0600 |
commit | 085e97d63c35449758a3c62da0674a03ba9e9912 (patch) | |
tree | c0368a48438e9dd24af9c232e3c8bd0ac8fff2d4 | |
parent | 47804933012841f2dc90626bdcc161adf34569a5 (diff) | |
download | node-new-085e97d63c35449758a3c62da0674a03ba9e9912.tar.gz |
doc: fix esm extension example with type module
-rw-r--r-- | doc/api/esm.md | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/doc/api/esm.md b/doc/api/esm.md index f3a34e7d46..1461379f6a 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -13,6 +13,19 @@ ECMAScript modules are [the official standard format][] to package JavaScript code for reuse. Modules are defined using a variety of [`import`][] and [`export`][] statements. +First, to enable modules in Node.js for `.js` extensions, ensure there is a +`package.json` file in the root of the project with `"type": "module"` set: + +```js +// package.json +{ + "name": "app", + "type": "module" +} +``` + +> An alternative to setting `"type": "module" is to use the `.mjs` extension. + The following example of an ES module exports a function: ```js |