docs(package-json): add documentation for type field by MaxBlack-dev · Pull Request #8793 · npm/cli · GitHub
Skip to content

docs(package-json): add documentation for type field - #8793

Merged
wraithgar merged 1 commit into
npm:latestfrom
MaxBlack-dev:docs/add-type-field
Dec 3, 2025
Merged

wraithgar merged 1 commit into
npm:latestfrom
MaxBlack-dev:docs/add-type-field

Conversation

@MaxBlack-dev

@MaxBlack-dev MaxBlack-dev commented Nov 30, 2025 •

Copy link
Copy Markdown
Contributor

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

  • Documentation update

@MaxBlack-dev
MaxBlack-dev requested a review from a team as a code owner November 30, 2025 01:37
@wraithgar

wraithgar commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

@MaxBlack-dev

Copy link
Copy Markdown
Contributor Author

@wraithgar
wraithgar merged commit 50508f9 into npm:latest Dec 3, 2025
8 checks passed
@github-actions github-actions Bot mentioned this pull request Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DOCS] package.json type field is undocumented

2 participants