diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 79e9b2446c6bbf..758f53544e2a59 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -14,6 +14,7 @@ const { ObjectDefineProperty, ObjectSetPrototypeOf, PromiseAll, + PromisePrototypeCatch, RegExpPrototypeExec, SafeArrayIterator, SafeWeakMap, @@ -525,9 +526,12 @@ class ESMLoader { .then(({ module }) => module.getNamespace()); } - const namespaces = await PromiseAll(new SafeArrayIterator(jobs)); + const namespaces = await PromisePrototypeCatch( + PromiseAll(new SafeArrayIterator(jobs)), + (err) => { throw err; }, // Make errors catchable in a custom loader. + ); - if (!wasArr) { return namespaces[0]; } // We can skip the pairing below + if (!wasArr) { return namespaces[0]; } // We can skip the pairing below. for (let i = 0; i < count; i++) { const namespace = ObjectCreate(null);