diff options
author | snek <snek@deno.com> | 2024-09-19 21:10:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-19 21:10:34 -0700 |
commit | a01dce3a25e0bf671c6c21bd6ff57861be613087 (patch) | |
tree | becb8a7c90e5a21e83c81160eec9d91e1281bc92 /ext/node/polyfills/01_require.js | |
parent | f1ba26661346a83b6e7fe5e7ffeed4553a9571ae (diff) |
fix: cjs resolution cases (#25739)
Fixes cjs modules being loaded as esm.
Diffstat (limited to 'ext/node/polyfills/01_require.js')
-rw-r--r-- | ext/node/polyfills/01_require.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/ext/node/polyfills/01_require.js b/ext/node/polyfills/01_require.js index e79f5a654..5b0980c31 100644 --- a/ext/node/polyfills/01_require.js +++ b/ext/node/polyfills/01_require.js @@ -1007,7 +1007,10 @@ Module.prototype._compile = function (content, filename, format) { try { compiledWrapper = wrapSafe(filename, content, this, format); } catch (err) { - if (err instanceof SyntaxError && op_require_can_parse_as_esm(content)) { + if ( + format !== "commonjs" && err instanceof SyntaxError && + op_require_can_parse_as_esm(content) + ) { return loadESMFromCJS(this, filename, content); } throw err; @@ -1067,7 +1070,7 @@ Module._extensions[".js"] = function (module, filename) { let format; if (StringPrototypeEndsWith(filename, ".js")) { const pkg = op_require_read_closest_package_json(filename); - if (pkg?.typ === "module") { + if (pkg?.type === "module") { format = "module"; } else if (pkg?.type === "commonjs") { format = "commonjs"; |