Commit 9842d3e
committed
module: fix extensionless CJS files in type:module packages
PR #61600 made the CJS loader respect the package.json type field for
extensionless files, which fixed #61104 but also enforced type: "module"
for extensionless files. This broke CJS extensionless files inside ESM
packages (e.g. yargs v17).
Only enforce type: "commonjs" for extensionless files. For type: "module",
leave format undefined so syntax detection handles it. This restores the
documented exception in the CJS documentation that has existed since v16:
extensionless files in type: "module" packages are recognized as CJS when
included via require().
Fixes: #61971
Refs: yargs/yargs#2509
Refs: #61600
PR-URL: #620831 parent f91cf7f commit 9842d3e
File tree
4 files changed
+18
-4
lines changed- lib/internal/modules/cjs
- test
- es-module
- fixtures/es-modules/extensionless-cjs-module
4 files changed
+18
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1952 | 1952 | | |
1953 | 1953 | | |
1954 | 1954 | | |
1955 | | - | |
1956 | | - | |
1957 | | - | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
1958 | 1958 | | |
1959 | 1959 | | |
1960 | | - | |
| 1960 | + | |
1961 | 1961 | | |
1962 | 1962 | | |
1963 | 1963 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments