diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 5e7095a75f63f5..d10aba4426ae60 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -462,6 +462,10 @@ function shouldUseESMLoader(mainPath) { const userLoader = getOptionValue('--experimental-loader'); if (userLoader) return true; + const experimentalSpecifierResolution = + getOptionValue('--experimental-specifier-resolution'); + if (experimentalSpecifierResolution === 'node') + return true; // Determine the module format of the main if (mainPath && mainPath.endsWith('.mjs')) return true; diff --git a/test/es-module/test-esm-specifiers.mjs b/test/es-module/test-esm-specifiers.mjs index 499a14643859a4..cf9a50353878de 100644 --- a/test/es-module/test-esm-specifiers.mjs +++ b/test/es-module/test-esm-specifiers.mjs @@ -1,6 +1,9 @@ // Flags: --experimental-modules --experimental-specifier-resolution=node import { mustNotCall } from '../common/index.mjs'; import assert from 'assert'; +import path from 'path'; +import { spawn } from 'child_process'; +import { fileURLToPath } from 'url'; // commonJS index.js import commonjs from '../fixtures/es-module-specifiers/package-type-commonjs'; @@ -33,3 +36,24 @@ async function main() { } main().catch(mustNotCall); + +// Test path from command line arguments +[ + 'package-type-commonjs', + 'package-type-module', + '/', + '/index', +].forEach((item) => { + const modulePath = path.join( + fileURLToPath(import.meta.url), + '../../fixtures/es-module-specifiers', + item, + ); + spawn(process.execPath, [ + '--experimental-modules', + '--es-module-specifier-resolution=node', + modulePath + ], { stdio: 'inherit' }).on('exit', (code) => { + assert.strictEqual(code, 0); + }); +});