module: fix extensionless CJS files in type:module packages#62083
Open
mcollina wants to merge 2 commits intonodejs:mainfrom
Open
module: fix extensionless CJS files in type:module packages#62083mcollina wants to merge 2 commits intonodejs:mainfrom
mcollina wants to merge 2 commits intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
PR nodejs#61600 made the CJS loader respect the package.json type field for extensionless files, but also enforced type: "module" which breaks CJS extensionless files inside ESM packages (e.g. yargs v17). Only enforce type: "commonjs" for extensionless files. For type: "module", leave format undefined so V8's syntax detection determines the correct format, allowing CJS extensionless files in ESM packages to continue working. Fixes: nodejs#61971 Refs: yargs/yargs#2509
3e6aa5a to
6e3ed67
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62083 +/- ##
=======================================
Coverage 89.64% 89.65%
=======================================
Files 676 676
Lines 206249 206326 +77
Branches 39518 39527 +9
=======================================
+ Hits 184892 184980 +88
+ Misses 13479 13471 -8
+ Partials 7878 7875 -3
🚀 New features to boost your workflow:
|
joyeecheung
approved these changes
Mar 3, 2026
Member
joyeecheung
left a comment
There was a problem hiding this comment.
Code LGTM with a correction on comment
Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com>
joyeecheung
approved these changes
Mar 3, 2026
Collaborator
watilde
approved these changes
Mar 3, 2026
marco-ippolito
approved these changes
Mar 3, 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.
Summary
package.jsontypefield for extensionless files, but also enforcedtype: "module"which breaks CJS extensionless files inside ESM packages (e.g. yargs v17)type: "commonjs"for extensionless files; fortype: "module", leave format undefined so V8's syntax detection determines the correct formatrequire()s a CJS extensionless file from atype: "module"package and verifies exports are correctTest plan
test/es-module/test-extensionless-esm-type-commonjs.jsstill passes (ESM syntax intype: "commonjs"still throws SyntaxError)type: "module"package returns correct exports viarequire()require()of fixture returns{ hello: 'world' }(was returning empty ESM namespace before fix)Fixes: #61971
Refs: yargs/yargs#2509
Refs: #61600