question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic remote throwing Container initialization failed as it has already been initialized with a different share scope

See original GitHub issue

Hi, 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:20 (11 by maintainers)

github_iconTop GitHub Comments

6reactions
jegor-cloudmorecommented, Aug 3, 2022

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

5reactions
AndreiSorokacommented, Aug 2, 2022

Hi! We have MF applications: HOST, A, B, C

Where dependencies: HOST <- A HOST <- B A <- C B <- C

image

So, when we load HOST <- A <- C, all is ok. After that when we change router (for example) and load HOST <- B <- C then we catch error

Dynamic remote throwing Container initialization failed as it has already been initialized with a different share scope

Because 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?

image

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?).

Read more comments on GitHub >

github_iconTop Results From Across the Web

shared module always report Container initialization failed as ...
But if navigate from one app to another, it will raise exception : Container initialization failed as it has already been initialized with...
Read more >
webpack: examples/module-federation/README.md - Fossies
shareScope ) throw new Error("Container initialization failed as it has already been initialized with a different share scope"); __webpack_require__.
Read more >
Module Federation. Advanced API in Webpack 5.0.0-beta.17
Module Federation was already powerful. ... Support of dynamic remotes ... Initialize the container, it may provide shared modules
Read more >
Module Federation - webpack
This object is used as a shared scope in the remote container and is filled ... to provide shared modules, but if the...
Read more >
ServletContext (Java(TM) EE 7 Specification APIs)
As of Java Servlet API 2.0, with no replacement. This method was originally defined to return an Enumeration of all the servlets known...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found