doc: remove extensionless CJS exception for type:module#62176
Open
mcollina wants to merge 4 commits intonodejs:mainfrom
Open
doc: remove extensionless CJS exception for type:module#62176mcollina wants to merge 4 commits intonodejs:mainfrom
mcollina wants to merge 4 commits intonodejs:mainfrom
Conversation
Remove the documented exception that extensionless files in type: "module" packages are recognized as CommonJS when included via require(). This exception conflicted with the ESM resolution specification which states that extensionless files within a package scope with an explicit type field follow the format of the type field. The behavior on main already matches the ESM spec since nodejs#61600, this change aligns the CJS documentation accordingly. Refs: nodejs#61600 Refs: nodejs#62083
Collaborator
|
Review requested:
|
joyeecheung
reviewed
Mar 10, 2026
doc/api/modules.md
Outdated
| [`"type"`][] with a value of `"module"`, those files will be recognized as | ||
| CommonJS modules only if they are being included via `require()`, not when | ||
| used as the command-line entry point of the program). | ||
| [`"type"`][] with a value of `"module"`, those files will not be recognized as |
Member
There was a problem hiding this comment.
I think we can just removed this entire point, because the opening paragraph says:
Node.js will treat the following as CommonJS modules
Instead, just add a new paragraph noting that files with extensions outside that set/files without extensions would be treated based on the type field in the package.json
Co-authored-by: Geoffrey Booth <webadmin@geoffreybooth.com>
Member
Author
|
@GeoffreyBooth I merged your edits. |
Member
I think something is buggy with the GitHub suggestions feature, because it looks like my suggestion got appended after the old text rather than replacing it:
|
GeoffreyBooth
approved these changes
Mar 22, 2026
GeoffreyBooth
approved these changes
Mar 22, 2026
UlisesGascon
approved these changes
Mar 23, 2026
Collaborator
Co-authored-by: Geoffrey Booth <webadmin@geoffreybooth.com>
Member
Author
|
@GeoffreyBooth ptal |
GeoffreyBooth
approved these changes
Apr 5, 2026
Member
GeoffreyBooth
left a comment
There was a problem hiding this comment.
Okay so just to confirm, in 26.0.0+:
- There are no more weird exceptions for extensionless files: they behave identically to
.jsfiles whether in atype: 'module'scope, atype: 'commonjs'scope, or a scope where there’s notypefield. - Syntax detection only ever applies within a scope where there’s no
typefield.
Is this correct?
ShogunPanda
approved these changes
Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The CJS documentation has included an exception since v16 (added in #41383) stating that extensionless files in
type: "module"packages are recognized as CommonJS when included viarequire(). This exception conflicts with the ESM resolution specification which states that extensionless files within a package scope with an explicittypefield follow the format of thetypefield.Since #61600, the behavior on
mainalready matches the ESM spec: extensionless files respect thetypefield. This change aligns the CJS documentation accordingly by removing the contradicting exception.For v25.x, #62083 restores the documented exception as a targeted fix to avoid breaking packages like yargs v17 that relied on the old behavior.
Refs: #61600
Refs: #62083
Refs: #61971