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

docs: add missing type field description for package.json #7897

Open
wants to merge 1 commit into
base: latest
Choose a base branch
from
Open
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