Skip to content

[webpack5-localization-plugin] Fix missing asset errors when localized chunks come from the cache - #6244

Open
Guru R Bharadwaj (guru-bharadwaj20) wants to merge 1 commit into
microsoft:mainfrom
guru-bharadwaj20:webpack5-localization-cached-files
Open

Guru R Bharadwaj (guru-bharadwaj20) wants to merge 1 commit into
microsoft:mainfrom
guru-bharadwaj20:webpack5-localization-cached-files

Conversation

@guru-bharadwaj20

Copy link
Copy Markdown

Summary

With realContentHash: true and a persistent or memory cache, a rebuild that reuses a cached localized chunk fails with Could not find asset "chunks/...-LOCALE.js" for chunk N. This happens in watch mode when you edit a module outside the localized chunk.

Fixes #6127

Details

processLocalizedAssetCachedAsync assigned the cached localizedFiles object directly to chunk.localizedFiles and returned it. The true hash step in trueHashes.ts later renames entries in that map in place, so it was also changing the object held in the cache. On the next build the cache returned the already renamed filenames, which no longer matched the assets emitted in that build.

The fix copies the map before using it, so the cached object stays as it was produced.

How it was tested

I added LocalizedAsyncCachedRebuild.test.ts. It builds twice with the same compiler and a memory cache, changing a non-localized module between builds. Before the fix the second build reports the two "Could not find asset" errors. After the fix both builds have no errors or warnings and the localized chunk names match. heft test --clean passes for the whole package.

Impacted documentation

None.

The realContentHash step renames entries of the chunk's localizedFiles
map in place. That map was the same object stored in the webpack cache,
so a rebuild that read the chunk from the cache got the renamed
filenames and failed with "Could not find asset".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the fix protecting cached localized filenames during rebuilds.

No open issues 🎉

What changed in this PR

Fixes #6127 by preventing real-content-hash processing from mutating cached localized filenames, avoiding missing-asset errors on rebuilds.

Changes:

  • Copies the cached filename map before attaching it to a chunk.
  • Adds a two-build memory-cache regression test.
  • Records a patch release note.
File Description
webpack/​webpack5-localization-plugin/​src/​test/​LocalizedAsyncCachedRebuild.test.ts Tests cached rebuilds after changing a non-localized module.
webpack/​webpack5-localization-plugin/​src/​AssetProcessor.ts Copies the filename map to protect cached entries.
common/​changes/​@rushstack/​webpack5-localization-plugin/​webpack5-localization-cached-files_2026-12-02-12-00.json Documents the rebuild fix for release.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

[webpack5-localization-plugin] Watch rebuild fails with 'Could not find asset ... for chunk ...' when realContentHash is on

2 participants