Skip to content

Conversation

@pull
Copy link

@pull pull bot commented Dec 4, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

Max Black and others added 3 commits December 3, 2025 12:34
## 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 <husivm@google.com>
@pull pull bot locked and limited conversation to collaborators Dec 4, 2025
@pull pull bot added the ⤵️ pull label Dec 4, 2025
@pull pull bot merged commit 50508f9 into LadyK-21:latest Dec 4, 2025
0 of 3 checks passed
@LadyK-21
Copy link
Owner

LadyK-21 commented Dec 4, 2025

⚠️ Snyk checks are incomplete.

Status Scanner Critical High Medium Low Total (0)
⚠️ Open Source Security 0 0 0 0 See details

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants