From 085e97d63c35449758a3c62da0674a03ba9e9912 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Thu, 14 May 2020 14:56:10 -0600 Subject: [PATCH 1/2] doc: fix esm extension example with type module --- doc/api/esm.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/api/esm.md b/doc/api/esm.md index f3a34e7d463e41..1461379f6a60f6 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 From ac011501afe96cb0ff0c625a0f05d490111a5750 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Thu, 14 May 2020 15:03:58 -0600 Subject: [PATCH 2/2] fix: skip package.json lint --- doc/api/esm.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/api/esm.md b/doc/api/esm.md index 1461379f6a60f6..c4d6cf0007cc14 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -16,6 +16,7 @@ code for reuse. Modules are defined using a variety of [`import`][] and 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 {