Skip to content

Commit f4c95e1

Browse files
author
Max Black
committed
docs: simplify type field documentation to reference Node.js docs
1 parent 9d44198 commit f4c95e1

File tree

1 file changed

+2
-25
lines changed

1 file changed

+2
-25
lines changed

docs/lib/content/configuring-npm/package-json.md

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -337,32 +337,9 @@ If `main` is not set, it defaults to `index.js` in the package's root folder.
337337

338338
### type
339339

340-
The `type` field defines the module format that Node.js should use for `.js` files in your package. It can have two values:
340+
The `type` field is used by Node.js to determine whether `.js` files should be treated as ES modules or CommonJS modules. This field is not used by npm directly.
341341

342-
* `"module"` - Tells Node.js to treat `.js` files as ES modules (ESM), allowing you to use `import` and `export` statements.
343-
* `"commonjs"` - Tells Node.js to treat `.js` files as CommonJS modules (the default), using `require()` and `module.exports`.
344-
345-
If the `type` field is not set, Node.js defaults to `"commonjs"`.
346-
347-
Example for an ES module package:
348-
349-
```json
350-
{
351-
"type": "module"
352-
}
353-
```
354-
355-
Example for a CommonJS package (explicit, though this is the default):
356-
357-
```json
358-
{
359-
"type": "commonjs"
360-
}
361-
```
362-
363-
**Note:** Regardless of the `type` field value, `.mjs` files are always treated as ES modules, and `.cjs` files are always treated as CommonJS modules.
364-
365-
For more information, see the [Node.js documentation on package.json type field](https://nodejs.org/api/packages.html#type).
342+
For detailed information about the `type` field, its possible values (`"module"` or `"commonjs"`), and how it affects module resolution, see the [Node.js documentation on the type field](https://nodejs.org/api/packages.html#type).
366343

367344
### browser
368345

0 commit comments

Comments
 (0)