esm: throw ERR_REQUIRE_ESM instead of ERR_INTERNAL_ASSERTION

PR-URL: https://github.com/nodejs/node/pull/54868
Backport-PR-URL: https://github.com/nodejs/node/pull/56927
Fixes: https://github.com/nodejs/node/issues/54773
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Refs: https://github.com/nodejs/node/issues/52697
This commit is contained in:
Antoine du Hamel authored and Marco Ippolito committed 2025-02-11 11:56:18 +01:00
1 parent d1331fccb2
commit 4813a6a66c
1 file changed
+3 -2
+3 -2
View File
@@ -318,8 +318,6 @@ class ModuleLoader {
* @returns {ModuleJobBase}
*/
getModuleJobForRequire(specifier, parentURL, importAttributes) {
assert(getOptionValue('--experimental-require-module'));
const parsed = URLParse(specifier);
if (parsed != null) {
const protocol = parsed.protocol;
@@ -338,6 +336,9 @@ class ModuleLoader {
}
const { url, format } = resolveResult;
if (!getOptionValue('--experimental-require-module')) {
throw new ERR_REQUIRE_ESM(url, true);
}
const resolvedImportAttributes = resolveResult.importAttributes ?? importAttributes;
let job = this.loadCache.get(url, resolvedImportAttributes.type);
if (job !== undefined) {