We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 27ba1cb commit 682ec4fCopy full SHA for 682ec4f
1 file changed
lib/internal/modules/cjs/loader.js
@@ -1929,6 +1929,14 @@ Module._extensions['.js'] = function(module, filename) {
1929
} else {
1930
format = 'typescript';
1931
}
1932
+ } else if (path.extname(filename) === '') {
1933
+ // Extensionless files skip the .js suffix check above. When type: commonjs
1934
+ // is explicit, force commonjs format so ESM syntax surfaces as SyntaxError
1935
+ // instead of silently delegating to ESM.
1936
+ pkg = packageJsonReader.getNearestParentPackageJSON(filename);
1937
+ if (pkg?.data?.type === 'commonjs') {
1938
+ format = 'commonjs';
1939
+ }
1940
1941
const { source, format: loadedFormat } = loadSource(module, filename, format);
1942
// Function require shouldn't be used in ES modules when require(esm) is disabled.
0 commit comments