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:

  1. Clone the repository
  2. Run npm install to install the dependencies
  3. Run npm run watch to start watching for changes
  4. Open the asset-manifest.json file in the public folder, and open the app chunk that is referenced in the entry-points field. Now look for the runtime-app chunk in the app chunk and check that it’s the same that is referenced in the asset-manifest.json file: it should be the same (with the same hash)
  5. Make a change to the code in app.js and save it
  6. The issue is still not there
  7. Now make a change to the design-area.js file and save it
  8. The issue should be there now: the runtime-app chunk in the asset-manifest.json file and in the app chunk 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)

Most upvoted comments

I’ve seen that the issue is closed and the PR got merged into the main repository, however the latest release (v5.99.9) happened one week earlier, so I suppose that I’m not getting the updates if I install the latest version, is that correct?

Yes, it is a part of 5.100.0 release

So, what’s gonna happen next? All the changes will be available after the next release? Is there an easy way to know when this is going to happen?

Hard to say, we have roadmap for 5.100.0 and 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

fix should be here - https://github.com/webpack/webpack/blob/main/lib/esm/ModuleChunkFormatPlugin.js#L206

Does it mean I just have to update to 5.99.9?

@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:

import __webpack_require__ from "./runtime-app.cd925ca1545fa8a9af92.js";

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