Commit 50508f9
docs(package-json): add documentation for type field (#8793)
## Description
This PR adds documentation for the `type` field in package.json, which
controls whether Node.js treats .js files as ES modules or CommonJS
modules.
## Changes
- Added a new section documenting the `type` field
- Explained the two possible values: `module` and `commonjs`
- Provided examples for both module types
- Added a note about .mjs and .cjs file extensions
- Linked to Node.js official documentation
## Fixes
Closes #8376
## Context
The `type` field is a crucial part of package.json for modern Node.js
projects, especially with the widespread adoption of ES modules. As
reported in issue #8376, this field was not documented in npm's
package.json reference, which caused confusion for developers trying to
understand how to configure their packages for ESM or CommonJS.
This documentation clarifies:
1. How to enable ES modules in a package (`"type": "module"`)
2. How to explicitly use CommonJS (`"type": "commonjs"`)
3. The default behavior when `type` is omitted (CommonJS)
4. That file extensions (.mjs/.cjs) override the type field
## Type of Change
- [x] Documentation update
Co-authored-by: Max Black <[email protected]>1 parent aa1dd7e commit 50508f9
1 file changed
+6
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
338 | 344 | | |
339 | 345 | | |
340 | 346 | | |
| |||
0 commit comments