| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f91cf7f commit ea87eea
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1952,12 +1952,12 @@ Module._extensions['.js'] = function(module, filename) { | |||
| 1952 | 1952 | format = 'typescript'; | |
| 1953 | 1953 | } | |
| 1954 | 1954 | } else if (path.extname(filename) === '') { | |
| 1955 | - // Extensionless files skip the .js suffix check above. When type is explicit, | ||
| 1956 | - // follow it so ESM syntax surfaces as SyntaxError for commonjs instead of | ||
| 1957 | - // silently delegating to ESM. | ||
| 1955 | + // Extensionless files skip the .js suffix check above. When type is commonjs, follow it so ESM | ||
| 1956 | + // syntax surfaces as SyntaxError. For type: module, leave format undefined so our syntax | ||
| 1957 | + // detection handles it (allowing CJS extensionless files in ESM packages). | ||
| 1958 | 1958 | pkg = packageJsonReader.getNearestParentPackageJSON(filename); | |
| 1959 | 1959 | const typeFromPjson = pkg?.data?.type; | |
| 1960 | - if (typeFromPjson === 'commonjs' || typeFromPjson === 'module') { | ||
| 1960 | + if (typeFromPjson === 'commonjs') { | ||
| 1961 | 1961 | format = typeFromPjson; | |
| 1962 | 1962 | } | |
| 1963 | 1963 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,3 +17,13 @@ spawnSyncAndAssert(process.execPath, [ | |||
| 17 | 17 | stdout: /script STARTED[\s\S]*v\d+\./, | |
| 18 | 18 | trim: true, | |
| 19 | 19 | }); | |
| 20 | + | ||
| 21 | + // CJS extensionless file inside a type: "module" package should work | ||
| 22 | + // when require()'d. Regression test for https://github.com/nodejs/node/issues/61971 | ||
| 23 | + spawnSyncAndAssert(process.execPath, [ | ||
| 24 | + '-e', `const m = require(${JSON.stringify( | ||
| 25 | + fixtures.path('es-modules', 'extensionless-cjs-module', 'index') | ||
| 26 | + )}); if (m.hello !== 'world') throw new Error('expected CJS exports, got: ' + JSON.stringify(m))`, | ||
| 27 | + ], { | ||
| 28 | + status: 0, | ||
| 29 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + module.exports = { hello: 'world' }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + { | ||
| 2 | + "type": "module" | ||
| 3 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments