Replies: 1 comment
-
I have encountered a similar issue . Below is something you can try: In the host webpack config: In your remotes webpack config: set the output.publicPath to "auto" reference: https://webpack.js.org/guides/public-path/#environment-based I am also happy to take a look if you could share a minimal reproducible example with me. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are working on replacing two older web apps with a new one, and our new app uses module federation in a micro frontend setup. Now, we want to load some micro frontends into the old apps that we are replacing, so that we can gradually replace old functionality with new.
The setup is as follows:
Old App - A React monolith where we want to replace parts with micro frontends form the new app
New App:
In the New App, the setup is as follows: There is one micro frontend per page in the app, which contains an entry point that will load Main. Main will then load the correct micro frontend based on the URL. This means that all micro frontends expect to run in the context of Main, so that they have access to the different functions exposed by main.
In the Old App, we load Main and Common, and wrap the old app in a provider that will add the necessary shared context. Then, if a user goes to
old.app/economy
, we load the economy component, and render it on the page.This setup works, except for one caveat:
Once the remoteEntry.js scripts for Common, Main and Economy are loaded into the Old App, the remotes try to load chunks for their dependencies, from the URL of the host. Let's say the old app is running on
localhost.old.app:3000
, and economy is running onlocalhost.new.app:3001/economy
. the Old App loads, and loadslocalhost.new.app:3001/economy/remoteEntry.js
just fine, but then will try to load dependencies fromlocalhost.old.app:3000/economy
, where they obviously don't exist.which is caused by
GET http://localhost.old.app:3000/economy/999.c43a85a7f11b81877b05.js net::ERR_ABORTED 404 (Not Found)
I have no idea why this is happening.
Module federation config for Old App (acting as host):
Module federation config for Economy (acting as remote):
Module federation config for Main (acting as host in the New App, but as a remote in the Old App):
ExternalProvider
from Main is imported into Old app this way:const ExternalProvider = React.lazy(() => import("main/ExternalProvider"));
, and used like this:If I set up a proxy in webpack-dev-server that proxies
/economy
tolocalhost.new.app:3001
, everything works as it should.Any ideas for what is wrong? Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions