Weboack 5 Module Federation error in shared
See original GitHub issueBug report
What is the current behavior?
webpack version: 5.37.0 react version: 17.0.2 react-dom version: 17.0.2
i created project for demostation my problem -> module_federation_test
I have two apps:
- host_app is app which render remote app on different port. it works on localhost:8080
- remote_app is app which rende only - hello world, good luck. it works on localhost:8081
And my projec didn’t work.
when i didn’t use shared i had error:
- Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
- 1. You might have mismatching versions of React and the renderer (such as React DOM)
- 2. You might be breaking the Rules of Hooks
- 3. You might have more than one copy of React in the same app
- ....... etc
when i used shared i had error:
- Uncaught Error: Shared module is not available for eager consumption: webpack/sharing/consume/default/react/react
- at Object.__webpack_require__.m.<computed> (consumes:132)
- at __webpack_require__ (bootstrap:24)
- ....... etc
in second option i used this config
for host_app
new ModuleFederationPlugin({
name: "host",
filename: 'static/js/remoteEntry.js',
remotes: {
remote_app: "remote_app@http://localhost:8081/static/js/remoteEntry.js",
},
shared: [
{
react: {
singleton: true,
eager: true,
requiredVersion: deps.react
},
"react-dom": {
singleton: true,
eager: true,
requiredVersion: deps["react-dom"]
}
}
]
})
for remote_app
new ModuleFederationPlugin({
name: 'remote_app',
library: { type: "var", name: 'remote_app' },
filename: 'static/js/remoteEntry.js',
exposes: {
"./RootApp": "./src/apps/RemoteApp",
},
shared: [
{
react: {
singleton: true,
eager: true,
requiredVersion: deps.react
},
"react-dom": {
singleton: true,
eager: true,
requiredVersion: deps["react-dom"]
}
}
]
})
I found infomation about eager react on react_eager, but it isn’t work
I need help. Maybe i don’t understand philosophy or other things which are important for solve my problem.
p.s I tried lots of option, but it didn’t work. I made test project on GitHub (link above in the problem description) when anyone can test their theory of the truthful version code.
Please don’t tell me that it is problem in react =)
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Module Federation - webpack
Troubleshooting. Uncaught Error: Shared module is not available for eager consumption. The application is eagerly executing an application ...
Read more >Webpack 5 module federation error handling - Stack Overflow
I've a micro frontends running on monorepo using nx CLI where in the host application I'm using module federation to get the remoteEntry.js ......
Read more >Webpack module federation is not working with eager shared ...
I was looking into Webpack 5 Module federation feature, and have some trouble understanding why my code does not work. The idea is...
Read more >Migrating Module Federation from Webpack 5.0.0-beta.16 to ...
Migrating Module Federation from Webpack 5.0.0-beta.16 to Webpack 5.0.0-beta.21 ... Uncaught Error: Shared module is not available for eager consumption:
Read more >Uncaught Error: Shared module is not available for eager ...
If you are trying to share modules between Module Federation microfrontends, you might face the following strange error.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@MaxusAdmin No problem, I am glad I can help.
Could you try remove the then statement? Also , if I run the code below does it work for you (it is modified based on the code you provided)? https://github.com/XiaofengXie16/module_federation_test @MaxusAdmin