diff --git a/Libraries/LibJS/Runtime/VM.cpp b/Libraries/LibJS/Runtime/VM.cpp index 5ce09f0d403..0761100a089 100644 --- a/Libraries/LibJS/Runtime/VM.cpp +++ b/Libraries/LibJS/Runtime/VM.cpp @@ -551,7 +551,10 @@ ThrowCompletionOr VM::link_and_eval_module(Badge, S ThrowCompletionOr VM::link_and_eval_module(CyclicModule& module) { auto filename = module.filename(); - module.load_requested_modules(nullptr); + auto& promise_capability = module.load_requested_modules(nullptr); + + if (auto const& promise = verify_cast(*promise_capability.promise()); promise.state() == Promise::State::Rejected) + return JS::throw_completion(promise.result()); dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Linking module {}", filename); auto linked_or_error = module.link(*this); diff --git a/Libraries/LibJS/Tests/modules/basic-modules.js b/Libraries/LibJS/Tests/modules/basic-modules.js index 23b61dbdad8..1fa49198889 100644 --- a/Libraries/LibJS/Tests/modules/basic-modules.js +++ b/Libraries/LibJS/Tests/modules/basic-modules.js @@ -219,6 +219,10 @@ describe("in- and exports", () => { expect(result.default).toBeInstanceOf(RegExp); expect(result.default.toString()).toBe(/foo/.toString()); }); + + test("importing a non-existent file results in a SyntaxError", () => { + expectedModuleToThrowSyntaxError("./i-do-no-exist.mjs", "Cannot find/open module"); + }); }); describe("loops", () => {