title: WP5 Module Federation: Singleton instantiated multiple times
body: <p>Unfortunately, my repro for this is in a complex proprietary project, so I will do my best to explain what is going on.</p>
  <p>The closest example project to my use-case is this one: <a href="https://github.com/module-federation/module-federation-examples/tree/master/dynamic-system-host" rel="noreferrer">https://github.com/module-federation/module-federation-examples/tree/master/dynamic-system-host</a>
  Essentially, I have an omnidirectional setup where a single Shell App consumes a set of Remote Apps. Remote Apps are discovered during runtime, and are hence not specified in the Webpack config.</p>
  <p>The Shell, as well as all Remotes, have a dependency on a shared library, my-shared-lib:</p>
  <pre><code>&quot;dependencies&quot;: {
      &quot;my-shared-lib&quot;: &quot;^1.0.0&quot;
  }
  </code></pre>
  <p>The Shell, in its Webpack config, exposes this lib as an eager singleton:</p>
  <pre><code>new ModuleFederationPlugin({
    name: 'shell',
    filename: 'shellDefinition.js',
    shared: {
        'my-shared-lib': { singleton: true, eager: true, requiredVersion: '^1.0.0' }
    },
  }),
  </code></pre>
  <p>The Remotes, in their configs, also have it as shared, but not eagerly:</p>
  <pre><code>new ModuleFederationPlugin({
    name: 'remoteNameHere',
    filename: 'remoteDefinition.js',
    exposes: {
      './app': path.join(modulePath, 'app.js'),
    },
    shared: {
        'my-shared-lib': { singleton: true, eager: false, requiredVersion: '^1.0.0' }
    },
  })
  </code></pre>
  <p>The problem is this: I have verified both by runtime debugging and inspecting the bundles generated by Webpack that this lib is being included and instantiated several times - once for the shell, and once for each remote. The code for the lib is even present in the bundle for the Remote which Webpack loads when fetching the exposed ./app.js.</p>
  <p>I am at a loss for understanding what is going on here. I have tried to also share every single dependency of my-shared-lib, but this does not help.</p>
  <p>My expectation would be that the Remotes use the instance of my-shared-lib which is shared by the Shell, rather than creating their own instances.</p>
  <p>Have I completely misunderstood how dependency sharing works, or am I doing something else wrong?</p>
  <p>It should be noted that both the Shell and the Remots all have single entry points.</p>