Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

docs: added type field in the documentation of package.json #1653

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

Open
anuj123upadhyay wants to merge 1 commit into npm:main
base: main
Choose a base branch
Loading
from anuj123upadhyay:doc/npm

Conversation

@anuj123upadhyay
Copy link

@anuj123upadhyay anuj123upadhyay commented Jul 1, 2025
edited
Loading

Add documentation for package.json type field

What / Why

This PR adds comprehensive documentation for the type field in package.json, which was previously undocumented in the npm CLI documentation. The type field is an important Node.js feature that determines how .js files are interpreted (as ES modules or CommonJS modules) and was missing from the official npm package.json documentation.

Changes made:

  • Added complete documentation for the type field between the exports and main sections
  • Included practical JSON examples for both "module" and "commonjs" values
  • Explained the behavior and implications of each type setting
  • Added details about file extension handling (.js, .mjs, .cjs)
  • Added reference to official Node.js documentation for additional details

This addition helps developers understand how to properly configure their packages for ES modules or CommonJS, which is crucial for modern Node.js development.

References

Fixes npm/cli#[8376] - Documents the missing type field in package.json

@anuj123upadhyay anuj123upadhyay requested a review from a team as a code owner July 1, 2025 07:14

### type

The `type` field defines the module format that Node.js should use for `.js` files in the package. When set to `"module"`, Node.js will treat `.js` files as ES modules. When set to `"commonjs"` (or when the field is omitted), Node.js will treat `.js` files as CommonJS modules.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think rather than all of this content, it should be nothing more than a link to https://nodejs.org/api/packages.html#type, so that there's not two sources of truth to keep up to date.

Copy link
Member

@wraithgar wraithgar Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generally the position we have also taken in other places in the docs. "nothing more" is a little extreme, some helpful copy explaining that the source of truth is found elsewhere would be appropriate.

ljharb reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sure, that works fine :-) just, nothing technical, ie that would need to be updated in the future.

This comment was marked as spam.

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@wraithgar wraithgar wraithgar left review comments

+2 more reviewers

@ljharb ljharb ljharb left review comments

@popchili popchili popchili left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[DOCS] package.json type field is undocumented

AltStyle によって変換されたページ (->オリジナル) /