<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto">When creating a new ModuleFederationPlugin with shared libraries, if one of the packages has a configuration of <code class="notranslate">singleton: true, requiredVersion: false</code>, it will produce a remote entry file that uses the "loadFallback" function to try and get the package. This can lead to package duplication if a newer version of the library is provided by this module (or another module).</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<p dir="auto">Sample repo: <a href="https://github.com/colacadstink/WebpackModuleFederationBug">https://github.com/colacadstink/WebpackModuleFederationBug</a></p>
<p dir="auto">The dist directory is created from the standard webpack.config.js, and the workingDist directory from the webpack.working.config.js file. The only differences between these files are the output directories and the requiredVersion of lodash.</p>
<p dir="auto">Note the differences between dist/remoteEntry.js and workingDist/remoteEntry.js, specifically on line 380:</p>
<ul dir="auto">
<li>The dist copy of the file is using the loadFallback function, which will always return the highest version number available, regardless of if another instance has already been created; this can lead to situations where more than one instance is constructed, breaking the singleton flag.</li>
<li>The workingDist copy uses the loadSingletonVersionCheckFallback function with a version argument of [0]. This will let us use whatever version of the package is currently loaded, regardless of version, which is the same behavior I'd expected with the requiredVersion being false.</li>
</ul>






<p dir="auto"><strong>What is the expected behavior?</strong></p>
<p dir="auto">I feel as if this should be acting similarly to what happens if the requiredVersion is set to '*', which causes the method used in the remote entry file to be "loadStrictSingletonVersionCheckFallback" with a version argument of <code class="notranslate">[0]</code> (which does work as expected).</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  v5.64.2<br>
Node.js version: Tested on v12.16.1 and v12.20.1<br>
Operating System: n/a, but definitely there on Windows<br>
Additional tools: I used Lodash for demonstration purposes, but there's nothing special about it.</p>
<p dir="auto">Now when webpack is well typed and provides 12000+ lines of typescript code, it would be great to have a type for the main configuration function - the one which is exported.</p>
<p dir="auto">Here is a question I asked a few days ago on StackOverflow: <a href="https://stackoverflow.com/questions/69584268/what-is-the-type-of-the-webpack-config-function-when-it-comes-to-typescript" rel="nofollow">https://stackoverflow.com/questions/69584268/what-is-the-type-of-the-webpack-config-function-when-it-comes-to-typescript</a></p>
<p dir="auto">Let me repeat it here:</p>
<p dir="auto">Currently when one exports an object from the config-file, the <code class="notranslate">Configuration</code> type can be used:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const config: Configuration = {
  mode: 'production',
  // ...
}"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">config</span>: <span class="pl-smi">Configuration</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-c1">mode</span>: <span class="pl-s">'production'</span><span class="pl-kos">,</span>
  <span class="pl-c">// ...</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">But what is the type for exporting the function? E.g.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export default (...): ... =&gt; {
  return {
    mode: 'production'
    // ...
  }
}"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">default</span> <span class="pl-kos">(</span>...<span class="pl-kos">)</span>: ... <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-kos">{</span>
    <span class="pl-c1">mode</span>: <span class="pl-s">'production'</span>
    <span class="pl-c">// ...</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Surprisingly, but I couldn't find the proper type among a bunch of the types provided for webpack in <a href="https://github.com/webpack/webpack/blob/main/types.d.ts">https://github.com/webpack/webpack/blob/main/types.d.ts</a></p>
<p dir="auto">If you followed the SO line above, you'd see the answer from Igor: <a href="https://stackoverflow.com/a/69608855/1223483" rel="nofollow">https://stackoverflow.com/a/69608855/1223483</a><br>
Basically he makes this job: implementing <em>missed</em> types.</p>
<p dir="auto">But how could they be missed?</p>