diff --git a/.changeset/green-crews-melt.md b/.changeset/green-crews-melt.md new file mode 100644 index 00000000000..98b11dd3641 --- /dev/null +++ b/.changeset/green-crews-melt.md @@ -0,0 +1,5 @@ +--- +'@module-federation/node': patch +--- + +fix: remove chunks from installedChunks on fail to enable retries diff --git a/packages/node/src/runtimePlugin.ts b/packages/node/src/runtimePlugin.ts index 3ea2dc94535..73ec86344ca 100644 --- a/packages/node/src/runtimePlugin.ts +++ b/packages/node/src/runtimePlugin.ts @@ -235,6 +235,15 @@ export const installChunk = ( } }; +// Hoisted utility function to remove a chunk on fail +export const deleteChunk = ( + chunkId: string, + installedChunks: { [key: string]: any }, +): boolean => { + delete installedChunks[chunkId]; + return true; +}; + // Hoisted function to set up webpack script loader export const setupScriptLoader = (): void => { __webpack_require__.l = ( @@ -297,7 +306,8 @@ export const setupChunkHandler = ( chunkId, __webpack_require__.federation.rootOutputDir || '', (err, chunk) => { - if (err) return reject(err); + if (err) + return deleteChunk(chunkId, installedChunks) && reject(err); if (chunk) installChunk(chunk, installedChunks); resolve(chunk); }, @@ -312,7 +322,8 @@ export const setupChunkHandler = ( chunkName, __webpack_require__.federation.initOptions.name, (err, chunk) => { - if (err) return reject(err); + if (err) + return deleteChunk(chunkId, installedChunks) && reject(err); if (chunk) installChunk(chunk, installedChunks); resolve(chunk); },