Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/lib/content/configuring-npm/package-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,29 @@ Both email and url are optional either way.

npm also sets a top-level "maintainers" field with your npm user info.

### type

This _optional_ field of value _string_ helps Node.js determine the module format used in the package, affecting _import_ and _export_ behavior.

By default, Node.js utilizes the [CommonJS modules](https://nodejs.org/docs/latest/api/modules.html#modules-commonjs-modules) system for files with a `.js` or `.cjs` extension regardless whether the `type` field was provided or not. To use the modern [ECMAScript modules](https://nodejs.org/docs/latest/api/esm.html) (AKA ES modules) system, a `.mjs` file extension is required.

In a package.json file, the `type` field currently accepts two values:

- `commonjs` (default): Specifies that `.js` files within the package should be treated as CommonJS modules.

- `module`: Specifies that `.js` files within the package should be treated as ES modules.

Example:

```json
// ECMAScript
{
"type": "module"
}
```

For more details see the [node.js documentation on package type](https://nodejs.org/api/packages.html#type)

### funding

You can specify an object containing a URL that provides up-to-date
Expand Down