diff --git a/libs/mf-runtime/src/lib/loader/dynamic-federation.ts b/libs/mf-runtime/src/lib/loader/dynamic-federation.ts index 06f2f113..2d639686 100644 --- a/libs/mf-runtime/src/lib/loader/dynamic-federation.ts +++ b/libs/mf-runtime/src/lib/loader/dynamic-federation.ts @@ -3,8 +3,8 @@ type Scope = unknown; type Factory = () => any; type Container = { - init(shareScope: Scope): void; - get(module: string): Factory; + init(shareScope: Scope): void | Promise; + get(module: string): Factory | Promise; }; let config: Manifest = {}; @@ -113,8 +113,8 @@ async function loadRemoteModuleEntry(remoteEntry: string): Promise { return Promise.resolve(); } return await import(/* webpackIgnore:true */ remoteEntry).then( - (container) => { - initRemote(container, remoteEntry); + async (container) => { + await initRemote(container, remoteEntry); containerMap[remoteEntry] = container; }, ); @@ -140,11 +140,15 @@ async function loadRemoteScriptEntry( script.onerror = reject; - script.onload = () => { + script.onload = async () => { const container = (window as unknown as Record)[ remoteName ] as Container; - initRemote(container, remoteName); + try { + await initRemote(container, remoteName); + } catch (error) { + reject(error); + } containerMap[remoteName] = container; resolve(); };