From ba3bf99130107a0e548ec748411277bb42862b87 Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Tue, 14 May 2024 16:09:19 -0400 Subject: [PATCH 1/2] module: default to commonjs when format cannot be detected --- lib/internal/modules/esm/get_format.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/internal/modules/esm/get_format.js b/lib/internal/modules/esm/get_format.js index cd5c88dce8e021..a5a37aecce9b8c 100644 --- a/lib/internal/modules/esm/get_format.js +++ b/lib/internal/modules/esm/get_format.js @@ -112,10 +112,8 @@ function getFileProtocolModuleFormat(url, context = { __proto__: null }, ignoreE default: { // The user did not pass `--experimental-default-type`. // `source` is undefined when this is called from `defaultResolve`; // but this gets called again from `defaultLoad`/`defaultLoadSync`. - if (getOptionValue('--experimental-detect-module')) { - const format = source ? - (containsModuleSyntax(`${source}`, fileURLToPath(url), url) ? 'module' : 'commonjs') : - null; + if (getOptionValue('--experimental-detect-module') && source) { + const format = containsModuleSyntax(`${source}`, fileURLToPath(url), url) ? 'module' : 'commonjs'; if (format === 'module') { // This module has a .js extension, a package.json with no `type` field, and ESM syntax. // Warn about the missing `type` field so that the user can avoid the performance penalty of detection. From e3770a71a57acaaee9874d50b18b58274d07b3e6 Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Tue, 14 May 2024 16:18:11 -0400 Subject: [PATCH 2/2] commonjs default --- lib/internal/modules/esm/get_format.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/modules/esm/get_format.js b/lib/internal/modules/esm/get_format.js index a5a37aecce9b8c..407cb398bbdb9e 100644 --- a/lib/internal/modules/esm/get_format.js +++ b/lib/internal/modules/esm/get_format.js @@ -152,8 +152,7 @@ function getFileProtocolModuleFormat(url, context = { __proto__: null }, ignoreE return 'commonjs'; } default: { // The user did not pass `--experimental-default-type`. - if (getOptionValue('--experimental-detect-module')) { - if (!source) { return null; } + if (getOptionValue('--experimental-detect-module') && source) { const format = getFormatOfExtensionlessFile(url); if (format === 'module') { return containsModuleSyntax(`${source}`, fileURLToPath(url), url) ? 'module' : 'commonjs';