Skip to content

fix: remove chunks from installedChunks on fail to enable retries #3686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-crews-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/node': patch
---

fix: remove chunks from installedChunks on fail to enable retries
15 changes: 13 additions & 2 deletions packages/node/src/runtimePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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);
},
Expand All @@ -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);
},
Expand Down
Loading