You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Webpack module federation breaks with multiple entrypoints #2692
Using webpack-dev-server instead of webpack should still support module federation with additional content tacked onto the remoteEntry by defining it as an additional entry.
Actual Behavior
Running "yarn start" to start webpack-dev-server breaks module federation and thus breaks the app in development mode.
For Bugs; How can we reproduce the behavior?
clone repository
ensure you're on branch "dynamic-host-remote"
run yarn on repo root
go into "dynamic-host-remote" directory
run yarn start in "dynamic-host-remote" directory
open localhost:3001 in the browser
encounter an error in the browser console that happens when executing app2/remoteEntry.js with the additional contents that were added to this entrypoint by webpack-dev-server
OPTIONAL: run yarn build && yarn serve and revisit localhost:3001 to see production build working just fine.
Okay, so the issue here is that WDS is likely appending its own entrypoint to the array / injecting a "require" to the hmr client. That typically serves as the entry module of an application. When ModuleFederation emits a remoteEnty with the same name as the entrypoint, they are merged.
This lets us attach initialization code, to federated remotes. something like changing publicPath.
webpack_public_path = new URL(document.currentScript.src).origin + "/";
The remote becomes 400kb big (usually like 5kb) and the module returned to the global is not __webpack_require__("webpack/container/entry/app1"); - therefore window.app1 will not be __webpack_require__("webpack/container/entry/app1"); and the federated API is never set to the global
@sokra i believe that either the WDS entry needs to return the container - which may lead to HMR capabilities? or the WDS entry module should not be applied to federated entry points when combined.
constprependEntry=(originalEntry,additionalEntries)=>{if(typeoforiginalEntry==='function'){return()=>Promise.resolve(originalEntry()).then((entry)=>prependEntry(entry,additionalEntries));}if(typeoforiginalEntry==='object'&&!Array.isArray(originalEntry)){/** @type {Object<string,string>} */constclone={};Object.keys(originalEntry).forEach((key)=>{// entry[key] should be a string hereconstentryDescription=originalEntry[key];if(typeofentryDescription==='object'&&entryDescription.import){clone[key]=Object.assign({},entryDescription,{import: prependEntry(entryDescription.import,additionalEntries),});}else{clone[key]=prependEntry(entryDescription,additionalEntries);}});
@ScriptedAlchemy Hello! Thank you for your reply. Wouldn't you mind sharing a piece of that config where you "fetch all remote URLs on a poll and hash them"? I'm not super aware of how to set up such config in webpack and it sounds a bit difficult to me to implement that so maybe some samples would be really helpful to me to understand that configuration and make live reloading in my case. Thank you again!
Correct. The issue is collision in the runtime. Loading the remote of the hot binds to the second chunk loading global and the host no longer gets the refresh updates
@ScriptedAlchemy sorry if this is OT, but would would the v2 webpack plugin be considered a drop-in replacement for the one currently bundled with webpack itself?
Try setting publicPath: "auto" in your webpack.config.js. This helps Webpack resolve URLs correctly when using webpack-dev-server, preventing issues with remoteEntry.js.
How to do it:
In your webpack.config.js, update the output section like this:
Activity
alexander-akait commentedon Aug 3, 2020
@webpack-bot move to webpack/webpack-dev-serverMy mistakealexander-akait commentedon Aug 3, 2020
Feel free to send a fix
codepunkt commentedon Aug 3, 2020
If I had a clue what the problem is, i'd send a PR right away. Spent a few hours with this, don't have the slightest idea 🤔
alexander-akait commentedon Aug 3, 2020
/cc @sokra Any ideas on this?
ScriptedAlchemy commentedon Aug 4, 2020
Okay, so the issue here is that WDS is likely appending its own entrypoint to the array / injecting a "require" to the hmr client. That typically serves as the entry module of an application. When ModuleFederation emits a remoteEnty with the same name as the entrypoint, they are merged.
This lets us attach initialization code, to federated remotes. something like changing publicPath.
webpack_public_path = new URL(document.currentScript.src).origin + "/";
module-federation/module-federation-examples#277
The remote becomes 400kb big (usually like 5kb) and the module returned to the global is not
__webpack_require__("webpack/container/entry/app1");- therefore window.app1 will not be__webpack_require__("webpack/container/entry/app1");and the federated API is never set to the global@sokra i believe that either the WDS entry needs to return the container - which may lead to HMR capabilities? or the WDS entry module should not be applied to federated entry points when combined.
sokra commentedon Aug 4, 2020
The wds entrypoint should be prepended instead of appended. The last value is exported.
ScriptedAlchemy commentedon Aug 4, 2020
Will take a look, thanks @sokra
ScriptedAlchemy commentedon Aug 4, 2020
Looks like we want to modify this
sokra commentedon Aug 5, 2020
It already prepends... So there is somethings else wrong
82 remaining items
IgorStetsiuk commentedon Feb 22, 2022
@ScriptedAlchemy Hello! Thank you for your reply. Wouldn't you mind sharing a piece of that config where you "fetch all remote URLs on a poll and hash them"? I'm not super aware of how to set up such config in webpack and it sounds a bit difficult to me to implement that so maybe some samples would be really helpful to me to understand that configuration and make live reloading in my case. Thank you again!
ScriptedAlchemy commentedon Mar 2, 2022
Fetch(jsUrl).then(text).then(md5hashFronString)
Store it on some object and put the fetch in a setInterval.
xujie-phper commentedon Aug 11, 2022
any updates, i face the same issue when use module federation
rdenman commentedon Apr 12, 2023
Since this issue is still open, I'll link to my (pretty damn hacky) "solution" for HMR I posted in another thread: webpack/webpack#11240 (comment)
It's very far from perfect, but it does the job in a pinch
ssuvorov commentedon Oct 20, 2023
20 October 2023 👀
tamilarasu602 commentedon Dec 20, 2024
For CRA, the reason HMR is not working is due to the issue mentioned in #3038 (comment)
The solution would be to override the webpack config using
cracoorreact-app-rewiredas followsScriptedAlchemy commentedon Dec 20, 2024
Correct. The issue is collision in the runtime. Loading the remote of the hot binds to the second chunk loading global and the host no longer gets the refresh updates
ScriptedAlchemy commentedon Dec 20, 2024
Note. Federation v2 supports hmr and fast refresh of remotes as well.
Module-federation.io
alexander-akait commentedon Dec 25, 2024
@ScriptedAlchemy can you point how do you resolve it?
ScriptedAlchemy commentedon Dec 25, 2024
Which issue?
Anubhab2003 commentedon Jan 3, 2025
Hey I am Interested in contributing this issue, How to get started ?
csvan commentedon Jan 3, 2025
@ScriptedAlchemy sorry if this is OT, but would would the v2 webpack plugin be considered a drop-in replacement for the one currently bundled with webpack itself?
ScriptedAlchemy commentedon Jan 4, 2025
Yes
BilalAhmedMalik1 commentedon Apr 3, 2025
Try setting publicPath: "auto" in your webpack.config.js. This helps Webpack resolve URLs correctly when using webpack-dev-server, preventing issues with remoteEntry.js.
How to do it:
In your webpack.config.js, update the output section like this:
output: {
publicPath: "auto", // Ensures correct URL resolution
}
This worked for me and might help others facing the same issue. Let me know if it helps or if there's another workaround! 😊
Jeston10 commentedon Jan 25, 2026
I want to work on this issue? How may i get started? May I work on it @ branch moderators?