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




<p dir="auto"><strong>What is the current behavior?</strong><br>
This ticket is not critical, since the <code class="notranslate">dist/production</code> env still works, but there seems to be some not needed redundancy.<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/1177434/169510303-15e703f1-0b1a-4875-b9f2-229ce00035cd.png"><img width="1220" alt="Screenshot 2022-05-20 at 12 31 28" src="https://user-images.githubusercontent.com/1177434/169510303-15e703f1-0b1a-4875-b9f2-229ce00035cd.png" style="max-width: 100%;"></a></p>
<p dir="auto">The map contains the the same chunk-names for many (not all) entries at the first and last position of the arrays.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong><br>
The easiest way to reproduce it:</p>
<ol dir="auto">
<li>clone the neo.mjs repository: <a href="https://github.com/neomjs/neo">https://github.com/neomjs/neo</a></li>
<li>npm install</li>
<li>npm run build-all</li>
<li>open dist/production/appworker.js</li>
</ol>






<p dir="auto"><strong>What is the expected behavior?</strong><br>
Chunk-names should be unique for each path / array. One easy way to fix it is probably to convert the array into a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set" rel="nofollow">Set</a> and back.</p>
<p dir="auto">it could make sense though to investigate why this is happening</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version: 5.72.1<br>
Node.js version: v16.2.0<br>
Operating System: Monterey<br>
Additional tools:</p>
<h1 dir="auto">Bug report</h1>
<p dir="auto">(I <em>think</em> this is a bug.  It's possible it's a feature I don't yet understand.)</p>
<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto">When using the split chunks plugin, the resulting compilation chunks sometimes have duplicate ids.   For example, I added this debugging hook to my webpack config:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  compiler.hooks.afterEmit.tap(&quot;log-dupe-chunks&quot;, function(compilation) {
    let chunks = compilation.chunks;
    let chunkIds = chunks.map(c =&gt; c.id);
    let dupeChunks = chunks
      .filter(c =&gt; chunkIds.filter(i =&gt; i === c.id).length &gt; 1)
      .map(c =&gt;
        pick(c, [&quot;id&quot;, &quot;ids&quot;, &quot;debugId&quot;, &quot;name&quot;, &quot;entryModule&quot;, &quot;files&quot;, &quot;rendered&quot;, &quot;hash&quot;, &quot;contentHash&quot;, &quot;renderedHash&quot;, &quot;chunkReason&quot;, &quot;extraAsync&quot;])
      );
    if (dupeChunks.length) {
      console.log(dupeChunks);
    }
  });
"><pre class="notranslate">  <span class="pl-s1">compiler</span><span class="pl-kos">.</span><span class="pl-c1">hooks</span><span class="pl-kos">.</span><span class="pl-c1">afterEmit</span><span class="pl-kos">.</span><span class="pl-en">tap</span><span class="pl-kos">(</span><span class="pl-s">"log-dupe-chunks"</span><span class="pl-kos">,</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">compilation</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-s1">chunks</span> <span class="pl-c1">=</span> <span class="pl-s1">compilation</span><span class="pl-kos">.</span><span class="pl-c1">chunks</span><span class="pl-kos">;</span>
    <span class="pl-k">let</span> <span class="pl-s1">chunkIds</span> <span class="pl-c1">=</span> <span class="pl-s1">chunks</span><span class="pl-kos">.</span><span class="pl-en">map</span><span class="pl-kos">(</span><span class="pl-s1">c</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">c</span><span class="pl-kos">.</span><span class="pl-c1">id</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">let</span> <span class="pl-s1">dupeChunks</span> <span class="pl-c1">=</span> <span class="pl-s1">chunks</span>
      <span class="pl-kos">.</span><span class="pl-en">filter</span><span class="pl-kos">(</span><span class="pl-s1">c</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">chunkIds</span><span class="pl-kos">.</span><span class="pl-en">filter</span><span class="pl-kos">(</span><span class="pl-s1">i</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">i</span> <span class="pl-c1">===</span> <span class="pl-s1">c</span><span class="pl-kos">.</span><span class="pl-c1">id</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">length</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">1</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">map</span><span class="pl-kos">(</span><span class="pl-s1">c</span> <span class="pl-c1">=&gt;</span>
        <span class="pl-en">pick</span><span class="pl-kos">(</span><span class="pl-s1">c</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-s">"id"</span><span class="pl-kos">,</span> <span class="pl-s">"ids"</span><span class="pl-kos">,</span> <span class="pl-s">"debugId"</span><span class="pl-kos">,</span> <span class="pl-s">"name"</span><span class="pl-kos">,</span> <span class="pl-s">"entryModule"</span><span class="pl-kos">,</span> <span class="pl-s">"files"</span><span class="pl-kos">,</span> <span class="pl-s">"rendered"</span><span class="pl-kos">,</span> <span class="pl-s">"hash"</span><span class="pl-kos">,</span> <span class="pl-s">"contentHash"</span><span class="pl-kos">,</span> <span class="pl-s">"renderedHash"</span><span class="pl-kos">,</span> <span class="pl-s">"chunkReason"</span><span class="pl-kos">,</span> <span class="pl-s">"extraAsync"</span><span class="pl-kos">]</span><span class="pl-kos">)</span>
      <span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">dupeChunks</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">dupeChunks</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Resulting in this output:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="[ { id: 'vendors~markdownediting~uploader',
    ids: [ 'vendors~markdownediting~uploader' ],
    debugId: 1011,
    name: 'lazy_store',
    entryModule: undefined,
    files:
     [ 'lazy_store.8122ea9e5a55db822e44.js',
       'lazy_store.8122ea9e5a55db822e44.js.map' ],
    rendered: true,
    hash: '8122ea9e5a55db822e44da03c4fa5547',
    contentHash: { javascript: '721f86d9054aaadb11d1' },
    renderedHash: '8122ea9e5a55db822e44',
    chunkReason: undefined,
    extraAsync: false },
  { id: 'vendors~markdownediting~uploader',
    ids: [ 'vendors~markdownediting~uploader' ],
    debugId: 1026,
    name: 'vendors~markdownediting~uploader',
    entryModule: undefined,
    files:
     [ 'vendors~markdownediting~uploader.bd57c5c4595c93582c8b.js',
       'vendors~markdownediting~uploader.bd57c5c4595c93582c8b.js.map' ],
    rendered: true,
    hash: 'bd57c5c4595c93582c8b9e692da052d0',
    contentHash: { javascript: 'c9f2f1d06758f3a354b1' },
    renderedHash: 'bd57c5c4595c93582c8b',
    chunkReason: 'split chunk (cache group: vendors) (name: vendors~markdownediting~uploader)',
    extraAsync: false } ]"><pre class="notranslate"><span class="pl-kos">[</span> <span class="pl-kos">{</span> <span class="pl-c1">id</span>: <span class="pl-s">'vendors~markdownediting~uploader'</span><span class="pl-kos">,</span>
    <span class="pl-c1">ids</span>: <span class="pl-kos">[</span> <span class="pl-s">'vendors~markdownediting~uploader'</span> <span class="pl-kos">]</span><span class="pl-kos">,</span>
    <span class="pl-c1">debugId</span>: <span class="pl-c1">1011</span><span class="pl-kos">,</span>
    <span class="pl-c1">name</span>: <span class="pl-s">'lazy_store'</span><span class="pl-kos">,</span>
    <span class="pl-c1">entryModule</span>: <span class="pl-c1">undefined</span><span class="pl-kos">,</span>
    <span class="pl-c1">files</span>:
     <span class="pl-kos">[</span> <span class="pl-s">'lazy_store.8122ea9e5a55db822e44.js'</span><span class="pl-kos">,</span>
       <span class="pl-s">'lazy_store.8122ea9e5a55db822e44.js.map'</span> <span class="pl-kos">]</span><span class="pl-kos">,</span>
    <span class="pl-c1">rendered</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
    <span class="pl-c1">hash</span>: <span class="pl-s">'8122ea9e5a55db822e44da03c4fa5547'</span><span class="pl-kos">,</span>
    <span class="pl-c1">contentHash</span>: <span class="pl-kos">{</span> <span class="pl-c1">javascript</span>: <span class="pl-s">'721f86d9054aaadb11d1'</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">renderedHash</span>: <span class="pl-s">'8122ea9e5a55db822e44'</span><span class="pl-kos">,</span>
    <span class="pl-c1">chunkReason</span>: <span class="pl-c1">undefined</span><span class="pl-kos">,</span>
    <span class="pl-c1">extraAsync</span>: <span class="pl-c1">false</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-kos">{</span> <span class="pl-c1">id</span>: <span class="pl-s">'vendors~markdownediting~uploader'</span><span class="pl-kos">,</span>
    <span class="pl-c1">ids</span>: <span class="pl-kos">[</span> <span class="pl-s">'vendors~markdownediting~uploader'</span> <span class="pl-kos">]</span><span class="pl-kos">,</span>
    <span class="pl-c1">debugId</span>: <span class="pl-c1">1026</span><span class="pl-kos">,</span>
    <span class="pl-c1">name</span>: <span class="pl-s">'vendors~markdownediting~uploader'</span><span class="pl-kos">,</span>
    <span class="pl-c1">entryModule</span>: <span class="pl-c1">undefined</span><span class="pl-kos">,</span>
    <span class="pl-c1">files</span>:
     <span class="pl-kos">[</span> <span class="pl-s">'vendors~markdownediting~uploader.bd57c5c4595c93582c8b.js'</span><span class="pl-kos">,</span>
       <span class="pl-s">'vendors~markdownediting~uploader.bd57c5c4595c93582c8b.js.map'</span> <span class="pl-kos">]</span><span class="pl-kos">,</span>
    <span class="pl-c1">rendered</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
    <span class="pl-c1">hash</span>: <span class="pl-s">'bd57c5c4595c93582c8b9e692da052d0'</span><span class="pl-kos">,</span>
    <span class="pl-c1">contentHash</span>: <span class="pl-kos">{</span> <span class="pl-c1">javascript</span>: <span class="pl-s">'c9f2f1d06758f3a354b1'</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">renderedHash</span>: <span class="pl-s">'bd57c5c4595c93582c8b'</span><span class="pl-kos">,</span>
    <span class="pl-c1">chunkReason</span>: <span class="pl-s">'split chunk (cache group: vendors) (name: vendors~markdownediting~uploader)'</span><span class="pl-kos">,</span>
    <span class="pl-c1">extraAsync</span>: <span class="pl-c1">false</span> <span class="pl-kos">}</span> <span class="pl-kos">]</span></pre></div>
<p dir="auto">Shouldn't that first chunk have an id of <code class="notranslate">lazy_store</code> ?</p>
<p dir="auto">I've only seen the duplicate chunk ids where one of the chunks is my code, the other chunk is vendor/node_modules code (see the <code class="notranslate">cache group: vendors</code> bit).</p>
<p dir="auto">I've also only seen this happen when using recordsPath.  If I delete my webpack records &amp; re-build, all the chunk ids are unique.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<p dir="auto">Sorry, I'm really struggling to narrow this down.  It seems to come and go at the whim of whatever heuristics drive SplitChunksPlugin.  If someone can confirm this is a bug and it's not immediately obvious why it happens, I'll try harder.</p>
<p dir="auto"><strong>What is the expected behavior?</strong></p>
<p dir="auto">Presumably all compilation chunks should have unique ids?</p>
<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  4.6.0<br>
Node.js version: 8.11.1<br>
Operating System: Docker with node:8.11-alpine</p>
<p dir="auto">I'm using <a href="https://github.com/GProst/webpack-clean-obsolete-chunks">https://github.com/GProst/webpack-clean-obsolete-chunks</a>, which expects chunks to have unique ids, and ends up accidentally deleting files when they don't.  If it turns out that chunks are allowed to have duplicate ids, I'll submit a fix to that.</p>