<p dir="auto">The new version of Sinon is throwing webpack for a loop again.  This code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    function makePublicAPI(require, exports, module) {
        module.exports = sinon;
        sinon.spy = require(&quot;./sinon/spy&quot;);
        sinon.spyCall = require(&quot;./sinon/call&quot;);
        sinon.behavior = require(&quot;./sinon/behavior&quot;);
        sinon.stub = require(&quot;./sinon/stub&quot;);
        sinon.mock = require(&quot;./sinon/mock&quot;);
        sinon.collection = require(&quot;./sinon/collection&quot;);
        sinon.assert = require(&quot;./sinon/assert&quot;);
        sinon.sandbox = require(&quot;./sinon/sandbox&quot;);
        sinon.test = require(&quot;./sinon/test&quot;);
        sinon.testCase = require(&quot;./sinon/test_case&quot;);
        sinon.match = require(&quot;./sinon/match&quot;);
    }

    if (isAMD) {
        define(makePublicAPI);
    } else if (isNode) {
        try {
            formatio = require(&quot;formatio&quot;);
        } catch (e) {}
        makePublicAPI(require, exports, module);         &lt;========
    }"><pre class="notranslate">    <span class="pl-k">function</span> <span class="pl-en">makePublicAPI</span><span class="pl-kos">(</span><span class="pl-s1">require</span><span class="pl-kos">,</span> <span class="pl-s1">exports</span><span class="pl-kos">,</span> <span class="pl-s1">module</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-s1">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-s1">sinon</span><span class="pl-kos">;</span>
        <span class="pl-s1">sinon</span><span class="pl-kos">.</span><span class="pl-c1">spy</span> <span class="pl-c1">=</span> <span class="pl-s1">require</span><span class="pl-kos">(</span><span class="pl-s">"./sinon/spy"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">sinon</span><span class="pl-kos">.</span><span class="pl-c1">spyCall</span> <span class="pl-c1">=</span> <span class="pl-s1">require</span><span class="pl-kos">(</span><span class="pl-s">"./sinon/call"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">sinon</span><span class="pl-kos">.</span><span class="pl-c1">behavior</span> <span class="pl-c1">=</span> <span class="pl-s1">require</span><span class="pl-kos">(</span><span class="pl-s">"./sinon/behavior"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">sinon</span><span class="pl-kos">.</span><span class="pl-c1">stub</span> <span class="pl-c1">=</span> <span class="pl-s1">require</span><span class="pl-kos">(</span><span class="pl-s">"./sinon/stub"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">sinon</span><span class="pl-kos">.</span><span class="pl-c1">mock</span> <span class="pl-c1">=</span> <span class="pl-s1">require</span><span class="pl-kos">(</span><span class="pl-s">"./sinon/mock"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">sinon</span><span class="pl-kos">.</span><span class="pl-c1">collection</span> <span class="pl-c1">=</span> <span class="pl-s1">require</span><span class="pl-kos">(</span><span class="pl-s">"./sinon/collection"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">sinon</span><span class="pl-kos">.</span><span class="pl-c1">assert</span> <span class="pl-c1">=</span> <span class="pl-s1">require</span><span class="pl-kos">(</span><span class="pl-s">"./sinon/assert"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">sinon</span><span class="pl-kos">.</span><span class="pl-c1">sandbox</span> <span class="pl-c1">=</span> <span class="pl-s1">require</span><span class="pl-kos">(</span><span class="pl-s">"./sinon/sandbox"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">sinon</span><span class="pl-kos">.</span><span class="pl-c1">test</span> <span class="pl-c1">=</span> <span class="pl-s1">require</span><span class="pl-kos">(</span><span class="pl-s">"./sinon/test"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">sinon</span><span class="pl-kos">.</span><span class="pl-c1">testCase</span> <span class="pl-c1">=</span> <span class="pl-s1">require</span><span class="pl-kos">(</span><span class="pl-s">"./sinon/test_case"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">sinon</span><span class="pl-kos">.</span><span class="pl-c1">match</span> <span class="pl-c1">=</span> <span class="pl-s1">require</span><span class="pl-kos">(</span><span class="pl-s">"./sinon/match"</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">isAMD</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-en">define</span><span class="pl-kos">(</span><span class="pl-s1">makePublicAPI</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">isNode</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">try</span> <span class="pl-kos">{</span>
            <span class="pl-s1">formatio</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"formatio"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span> <span class="pl-k">catch</span> <span class="pl-kos">(</span><span class="pl-s1">e</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
        <span class="pl-en">makePublicAPI</span><span class="pl-kos">(</span><span class="pl-en">require</span><span class="pl-kos">,</span> <span class="pl-s1">exports</span><span class="pl-kos">,</span> <span class="pl-smi">module</span><span class="pl-kos">)</span><span class="pl-kos">;</span>         <span class="pl-c1">&lt;</span><span class="pl-c1">=</span><span class="pl-c1">===</span><span class="pl-c1">===</span><span class="pl-c1">=</span>
    <span class="pl-kos">}</span></pre></div>
<p dir="auto">Is causing this warning:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="WARNING in ./~/sinon/lib/sinon.js
Critical dependencies:
365:22-29 require function is used in a way, in which dependencies cannot be statically extracted
 @ ./~/sinon/lib/sinon.js 365:22-29"><pre class="notranslate"><code class="notranslate">WARNING in ./~/sinon/lib/sinon.js
Critical dependencies:
365:22-29 require function is used in a way, in which dependencies cannot be statically extracted
 @ ./~/sinon/lib/sinon.js 365:22-29
</code></pre></div>
<p dir="auto">It's not obvious to me how to work around this.  Any of you have any bright ideas?</p>
<p dir="auto">(the line number indicated in the error, 365, is clearly wrong, and the line with the arrow is actually the offending code)</p>
<p dir="auto"><strong>I'm submitting a bug report</strong></p>
<p dir="auto"><strong>Webpack version:</strong><br>
1.13.1</p>
<p dir="auto"><strong>Please tell us about your environment:</strong><br>
Linux</p>
<p dir="auto"><strong>Current behavior:</strong><br>
Trying to get code split between multiple entry points, with each entry point split into own code and vendor bundle, then commons extracted for both own code and vendor bundles.</p>
<p dir="auto">Entry points look like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        entry: {
            login: './src/Login/index.jsx',
            app: './src/index.jsx',
            vendor: Object.keys(packageDotJson.dependencies).filter(function (element) {
                return element !== 'font-awesome' &amp;&amp; element !== 'jspdf';
            }),
            loginvendor: packageDotJson.loginDependencies
        },"><pre class="notranslate"><code class="notranslate">        entry: {
            login: './src/Login/index.jsx',
            app: './src/index.jsx',
            vendor: Object.keys(packageDotJson.dependencies).filter(function (element) {
                return element !== 'font-awesome' &amp;&amp; element !== 'jspdf';
            }),
            loginvendor: packageDotJson.loginDependencies
        },
</code></pre></div>
<p dir="auto">The following works as expected:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            new webpack.optimize.CommonsChunkPlugin({
                name: &quot;vendor&quot;,
                chunks: [&quot;app&quot;],
                minChunks: Infinity
            }),
            new webpack.optimize.CommonsChunkPlugin({
                name: &quot;loginvendor&quot;,
                chunks: [&quot;login&quot;],
                minChunks: Infinity
            }),
            new webpack.optimize.CommonsChunkPlugin({
                name: &quot;vendor.commons&quot;,
                chunks: [&quot;vendor&quot;, &quot;loginvendor&quot;],
                minChunks: 2
            }),"><pre class="notranslate"><code class="notranslate">            new webpack.optimize.CommonsChunkPlugin({
                name: "vendor",
                chunks: ["app"],
                minChunks: Infinity
            }),
            new webpack.optimize.CommonsChunkPlugin({
                name: "loginvendor",
                chunks: ["login"],
                minChunks: Infinity
            }),
            new webpack.optimize.CommonsChunkPlugin({
                name: "vendor.commons",
                chunks: ["vendor", "loginvendor"],
                minChunks: 2
            }),
</code></pre></div>
<p dir="auto">Vendor bundles are extracted from each entry point bundle, then a common vendor bundle is extracted from the two vendor bundles.</p>
<p dir="auto">Grepping the build results for definitions of commonly used packages like babal-polyfill and React, they are correctly found only in vendor.commons file.</p>
<p dir="auto">Adding:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            new webpack.optimize.CommonsChunkPlugin({
                name: &quot;commons&quot;,
                chunks: [&quot;app&quot;, &quot;login&quot;],
                minChunks: 2
            }),"><pre class="notranslate"><code class="notranslate">            new webpack.optimize.CommonsChunkPlugin({
                name: "commons",
                chunks: ["app", "login"],
                minChunks: 2
            }),
</code></pre></div>
<p dir="auto">and testing for the same packages, we have:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt; grep -R &quot;var React = {&quot; ./dist -l
./dist/vendor.commons.080acb7415d897182eca.js
./dist/commons.080acb7415d897182eca.js"><pre class="notranslate"><code class="notranslate">&gt; grep -R "var React = {" ./dist -l
./dist/vendor.commons.080acb7415d897182eca.js
./dist/commons.080acb7415d897182eca.js
</code></pre></div>
<p dir="auto">It seems the final invoking of the plugin is selecting the original app and login chunks, as they were before vendor modules were removed into vendor and loginvendor chunks.</p>
<p dir="auto"><strong>Expected/desired behavior:</strong><br>
Expecting</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            new webpack.optimize.CommonsChunkPlugin({
                name: &quot;commons&quot;,
                chunks: [&quot;app&quot;, &quot;login&quot;],
                minChunks: 2
            }),"><pre class="notranslate"><code class="notranslate">            new webpack.optimize.CommonsChunkPlugin({
                name: "commons",
                chunks: ["app", "login"],
                minChunks: 2
            }),
</code></pre></div>
<p dir="auto">to select the app and login chunks with vendor modules removed and extract the common modules from them into commons chunk. Vendor modules shouldn't appear both in commons and vendor.commons chunks.</p>
<ul dir="auto">
<li><strong>What is the motivation / use case for changing the behavior?</strong></li>
</ul>
<p dir="auto">It seems logical to expect that instances of the plugin will be ran sequentially and that every run will have access to chunks modified by the previous run.</p>
<p dir="auto">This specific use case if for production build. We need vendor code in separate bundles to avoid generating sourcemaps for it. Multiple entry points are needed to avoid serving a lot of unnecessary code to the user. Common modules are extracted to avoid duplication.</p>
<ul dir="auto">
<li><strong>Browser:</strong> [ Chrome 52.0.2743.116 (64-bit) ]</li>
<li><strong>Language:</strong> [ ES6/7 ]</li>
</ul>