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




<p dir="auto"><strong>What is the current behavior?</strong><br>
On webpack 5, The global array <code class="notranslate">self["webpackChunkxxx"]</code> may contain same chunk more times when using splitChunks. When using webpack 4, it runs ok.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<blockquote>
<p dir="auto">or see <a href="https://github.com/zphhhhh/webpack-bug">https://github.com/zphhhhh/webpack-bug</a> only well~</p>
</blockquote>
<p dir="auto">we use a global array like <code class="notranslate">self["webpackChunkxxx"]</code> to cache existing chunks, but it contains same chunk more times because <code class="notranslate">parentChunkLoadingFunction(data);</code>, see the output code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var webpackJsonpCallback = (data) =&gt; {
  // ...
  if (runtime) runtime(__webpack_require__);
  parentChunkLoadingFunction(data);
  while (resolves.length) {
    resolves.shift()();
  }

  // add entry modules from loaded chunk to deferred list
  if (executeModules) deferredModules.push.apply(deferredModules, executeModules);

  // run deferred modules when all chunks ready
  return checkDeferredModules();
}

var chunkLoadingGlobal = self[&quot;webpackChunkwebpack_bug&quot;] = self[&quot;webpackChunkwebpack_bug&quot;] || [];
var parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);
chunkLoadingGlobal.push = webpackJsonpCallback;"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-en">webpackJsonpCallback</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-c">// ...</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">runtime</span><span class="pl-kos">)</span> <span class="pl-en">runtime</span><span class="pl-kos">(</span><span class="pl-s1">__webpack_require__</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-en">parentChunkLoadingFunction</span><span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-k">while</span> <span class="pl-kos">(</span><span class="pl-s1">resolves</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-s1">resolves</span><span class="pl-kos">.</span><span class="pl-en">shift</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>

  <span class="pl-c">// add entry modules from loaded chunk to deferred list</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">executeModules</span><span class="pl-kos">)</span> <span class="pl-s1">deferredModules</span><span class="pl-kos">.</span><span class="pl-c1">push</span><span class="pl-kos">.</span><span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-s1">deferredModules</span><span class="pl-kos">,</span> <span class="pl-s1">executeModules</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

  <span class="pl-c">// run deferred modules when all chunks ready</span>
  <span class="pl-k">return</span> <span class="pl-en">checkDeferredModules</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">var</span> <span class="pl-s1">chunkLoadingGlobal</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span><span class="pl-kos">[</span><span class="pl-s">"webpackChunkwebpack_bug"</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span><span class="pl-kos">[</span><span class="pl-s">"webpackChunkwebpack_bug"</span><span class="pl-kos">]</span> <span class="pl-c1">||</span> <span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">parentChunkLoadingFunction</span> <span class="pl-c1">=</span> <span class="pl-s1">chunkLoadingGlobal</span><span class="pl-kos">.</span><span class="pl-c1">push</span><span class="pl-kos">.</span><span class="pl-en">bind</span><span class="pl-kos">(</span><span class="pl-s1">chunkLoadingGlobal</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">chunkLoadingGlobal</span><span class="pl-kos">.</span><span class="pl-c1">push</span> <span class="pl-c1">=</span> <span class="pl-en">webpackJsonpCallback</span><span class="pl-kos">;</span></pre></div>






<p dir="auto"><strong>What is the expected behavior?</strong></p>
<blockquote>
</blockquote>
<p dir="auto">The global array <code class="notranslate">self["webpackChunkxxx"]</code> should contain same chunk just one time,<br>
and <strong>when using webpack 4, it runs ok</strong></p>
<p dir="auto">You could change deps to webpack 4 in the Repo <a href="https://github.com/zphhhhh/webpack-bug">https://github.com/zphhhhh/webpack-bug</a> , then it runs ok.</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  latest, 5.10.0<br>
Node.js version: v12.18.2<br>
Operating System: macOS 10.15.6<br>
Additional tools:</p>
<p dir="auto"><strong>I'm submitting a feature request</strong><br>
webpack 2.1.0-beta.15<br>
Windows 10</p>
<p dir="auto"><strong>Current behavior:</strong><br>
<code class="notranslate">webpack --color</code> uses webpack.config.js and packs my project displaying color on the terminal<br>
<code class="notranslate">webpack</code> packs my project, ts-loader still shows color<br>
<code class="notranslate">webpack --colors</code> shows help and usage information<br>
along with error "Unknown argument: colors"</p>
<p dir="auto"><strong>Expected/desired behavior:</strong><br>
<code class="notranslate">webpack --color</code> shows same</p>
<ul dir="auto">
<li><strong>If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with a gist/jsbin of your webpack configuration.</strong></li>
<li><strong>What is the expected behavior?</strong></li>
<li><strong>What is the motivation / use case for changing the behavior?</strong></li>
<li><strong>Browser:</strong> [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]</li>
<li><strong>Language:</strong> [all | TypeScript X.X | ES6/7 | ES5 | Dart | ...]</li>
</ul>