webpack-cli icon indicating copy to clipboard operation
webpack-cli copied to clipboard

serve with multi-server doesn't work with Module Federation

Open Christian24 opened this issue 3 years ago • 0 comments

Describe the bug

Hello,

I don't know if this is the correct, project and a few problems that all seem to be related to either webpack-cli or webpack-dev-server, so please excuse if this is not the correct place.

General overview:

We are building multiple SPAs and we use multi-server for our development environment. This works, but now we want to introduce module federation. I added configurations for two federated modules and this is where problems began. To emulate our production environment I need to set publicPath on all configurations, so that they can run on the same port.

What is the current behavior? Adding two module federation configurations and setting their publicPath option, I get a ScriptLoadError. Upon further investigation it seems that the remoteEntry.js files both located under /app2/remoteEntry.js and /app3/remoteEntry.jsare identical.

To Reproduce

Steps to reproduce the behavior:

I created a reproduction here: https://stackblitz.com/edit/github-f36ynq?file=app1/webpack.config.js

Just look at the /app2/remoteEntry.js and /app3/remoteEntry.js. They should be identical, even though one wouldn't expect that.

Expected behavior

The correct remoteEntry.js files should be served.

Additional context

I can avoid the error by renaming the second remoteEntry.js to something else it seems. Then both files are correctly served. However, then webpack has problems loading additional chunks. I can solve this by setting the absolute path for publicPath like https://localhost:8080/app2/. However, in this scenario dependency sharing doesn't work. The urls webpack tries to load from somewhere contain undefined within the url. So, for now I had to disable dependency sharing in development.

I know publicPath: 'auto' should be used with module federation. However, setting that I am not able to setup my remotes the way I need to simulate a single server that is serving our assets.

Not sure, but maybe this is somewhat related to #2408?

Any advice would be greatly appreciated.

Christian24 avatar Aug 26 '22 16:08 Christian24