Dynamic remote throwing Container initialization failed as it has already been initialized with a different share scope
See original GitHub issueHi, First thanks a lot for giving us module federation. It is working really well for me. I was inspired by the dynamic remote example and I tried to implement that because i have 22 mfe and loading 22 remoteEntry.js file at once increases the initial render time. I followed the same approach as mentioned in the example but facing the above issue. My scenario also bit weird such that one mfe is library kind of thing. So all other 21 mfe use that library mfe.
Config for shell:
new ModuleFederationPlugin({
name: 'shell',
remotes: {
app_library: app_library@app_library/remoteEntry.js,
},
.......
})
Config for remaning MFEs:
new ModuleFederationPlugin({
name: <respective name>,
filename: 'remoteEntry.js',
library: { type: 'var', name: <respective name>},
exposes: {
...exposedPaths,
},
remotes: {
app_library: 'app_library',
},
},
})
Config for app_library:
new ModuleFederationPlugin({
name: app_library,
filename: 'remoteEntry.js',
library: { type: 'var', name: 'app_library' },
exposes: {
...exposedPaths,
},
})
Low level api’s used:
await __webpack_init_sharing__('default')
const container = (window as any)[remoteName] as Container
await container.init(__webpack_share_scopes__.default)
const factory = await container.get(exposedModule)
const Module = factory()
return Module as T
Issue Facing:
On loading Shell alone things (which loads app_library mfe too) works fine. But when I try to load other mfe through lazy routing it is throwing below error because app_library is already loaded. And stops there without navigating further.
sharing:17 Initialization of sharing external failed: Error: Container initialization failed as it has already been initialized with a different share scope
Expectation:
Instead of trying to initialize again it should use already initialized with or without warning and proceed.
Note:
Not sure it is a bug or feature request or question for stack overflow. Since I don’t find any example for my scenario posting here.
Thanks in advance
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:20 (11 by maintainers)
Top GitHub Comments
Have similar problem, where dependencies: HOST(MAIN) <- HOST/REMOTE(A) <- REMOTE© HOST(MAIN) <- HOST/REMOTE(B) <- REMOTE©
HOST/REMOTE uses webpack config. REMOTE uses webpack config. HOST uses vite config.
When component C called second time from different remote, then error is thrown.
Dynamic remote throwing Container initialization failed as it has already been initialized with a different share scope
Hi! We have MF applications: HOST, A, B, C
Where dependencies:
HOST <- A
HOST <- B
A <- C
B <- C
So, when we load
HOST <- A <- C
, all is ok. After that when we change router (for example) and loadHOST <- B <- C
then we catch errorBecause module
C
was initialized before. But I don’t understand, why do we think that these are different scopes? Do Module Federation support this case from a plugin?So, please, can you help find a solution to how I can resolve it?
P.s. my vision: it is should support by the MF plugin. We have one URL for bundle module
C
, and we have one scope (maybe need to deep check, but not equal link to object?).