doc: remove extensionless CJS exception for type:module#62176
doc: remove extensionless CJS exception for type:module#62176mcollina wants to merge 3 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
|
Review requested:
|
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 |
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>
|
@GeoffreyBooth I merged your edits. |
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:
|
|
|
||
| See [Determining module system][] for more details. |
There was a problem hiding this comment.
Did you mean to delete this line?
There was a problem hiding this comment.
yes. It’s a bullet point list. Should I move after the last bullet point?
There was a problem hiding this comment.
I think it was fine as is? There’s already a non-bulleted paragraph after this one, within this section.

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