From dc9f175f291e98c173c4b76f231a295cbf05d9da Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 11 Apr 2024 14:35:41 +0200 Subject: [PATCH] fixup! module: detect ESM syntax by trying to recompile as SourceTextModule --- lib/internal/modules/run_main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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;