From a01dce3a25e0bf671c6c21bd6ff57861be613087 Mon Sep 17 00:00:00 2001 From: snek Date: Thu, 19 Sep 2024 21:10:34 -0700 Subject: fix: cjs resolution cases (#25739) Fixes cjs modules being loaded as esm. --- ext/node/polyfills/01_require.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'ext') 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"; -- cgit v1.2.3