webpack: Main chunk points to the wrong runtime chunk when using Module Federation
Bug report
What is the current behavior?
When running the watch command, at some point the runtime-app chunk referenced in the app chunk is different from the one referenced in the asset-manifest.json.
Since we load this code in a PHP app, we use the manifest to load the chunks dynamically.
Having the manifest reference a different chunk than the one referenced in the app chunk means that the browser loads two different runtime-app chunks, one requested by the manifest, and the other by the app chunk.
Since the second one is the oldest, the end result is that the watch command is not doing its job, because from a certain moment, I’m not able to see the changes I make to the code reflected in the browser.
If the current behavior is a bug, please provide the steps to reproduce.
Here is a GitHub repository with the code needed to reproduce the issue: https://github.com/gtempesta/webpack-issue-repro/.
How to reproduce:
- Clone the repository
- Run
npm installto install the dependencies - Run
npm run watchto start watching for changes - Open the
asset-manifest.jsonfile in the public folder, and open theappchunk that is referenced in theentry-pointsfield. Now look for theruntime-appchunk in theappchunk and check that it’s the same that is referenced in theasset-manifest.jsonfile: it should be the same (with the same hash) - Make a change to the code in
app.jsand save it - The issue is still not there
- Now make a change to the
design-area.jsfile and save it - The issue should be there now: the
runtime-appchunk in theasset-manifest.jsonfile and in theappchunk should have different hashes
The issue happens only when using the watch command, and not when using the build command (which is not implemented in this repo).
What is the expected behavior?
I would expect that the runtime-app chunk referenced in the asset-manifest.json file and in the app chunk are always the same, so that I can use the manifest to load the chunks dynamically without having to worry about which one is loaded.
Other relevant information: webpack version: 5.99.5 Node.js version: 18.17.1 Operating System: macOS Sequoia 15.3.2 Additional tools:
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (9 by maintainers)
Yes, it is a part of
5.100.0releaseHard to say, we have roadmap for
5.100.0and we need to finish it before release, but it will be this month, anyway you can use version of Github in your package.json and get the latest version with fixes@gtempesta-pixartprinting Sorry, we’re still working on the fix. We’ll notify you once the patched version is released.
Shorty, because we generate this code in the chunk code to load runtime logic:
we don’t consider runtime chunk hash and including chunks (and modules) (due to this content hash doesn’t work too), ideally we need to get runtime chunk of current chunk, then get all chunks from runtime (and nested) and consider them as a part of chunk hash, fix should be here - https://github.com/webpack/webpack/blob/main/lib/esm/ModuleChunkFormatPlugin.js#L206
I will look deeply soon at this