diff --git a/lib/internal/modules/run_main.js b/lib/internal/modules/run_main.js index fa93e54456de3c..1ffbdb485db28c 100644 --- a/lib/internal/modules/run_main.js +++ b/lib/internal/modules/run_main.js @@ -2,8 +2,8 @@ const { ObjectGetPrototypeOf, - SyntaxErrorPrototype, StringPrototypeEndsWith, + SyntaxErrorPrototype, globalThis, } = primordials; @@ -174,7 +174,7 @@ function executeUserEntryPoint(main = process.argv[1]) { // Module._load is the monkey-patchable CJS module loader. Module._load(main, null, true); } catch (error) { - if (ObjectGetPrototypeOf(error) === SyntaxErrorPrototype) { + if (error != null && ObjectGetPrototypeOf(error) === SyntaxErrorPrototype) { const { shouldRetryAsESM } = internalBinding('contextify'); const mainPath = resolvedMain || main; mainURL = pathToFileURL(mainPath).href;