Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: fix esm extension example with type module #33409

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/api/esm.md
Expand Up @@ -13,6 +13,20 @@ 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:

<!-- eslint-skip -->
```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
Expand Down