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




<p dir="auto"><strong>What is the current behavior?</strong><br>
Server should get start without any error with <strong>webpackPrefetch</strong> in dynamic import. But it is failed to start if the webpack version is &gt;= 5.25.0 and it is working fine if webpack version &lt;= 5.24.0.</p>
<p dir="auto">Got below error while starting server</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/Users/Documents/dev/product/build/server.js:21367
/******/ webpack_require.O(0, [&quot;server&quot;], () =&gt; (), 5);
^

SyntaxError: Unexpected token ')'
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47"><pre class="notranslate"><span class="pl-pds"><span class="pl-c1">/</span>Users<span class="pl-c1">/</span></span><span class="pl-v">Documents</span><span class="pl-c1">/</span><span class="pl-s1">dev</span><span class="pl-c1">/</span><span class="pl-s1">product</span><span class="pl-c1">/</span><span class="pl-s1">build</span><span class="pl-c1">/</span><span class="pl-s1">server</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">21367</span>
<span class="pl-c">/******/</span> <span class="pl-s1">webpack_require</span><span class="pl-kos">.</span><span class="pl-en">O</span><span class="pl-kos">(</span><span class="pl-c1">0</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-s">"server"</span><span class="pl-kos">]</span><span class="pl-kos">,</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-kos">)</span><span class="pl-kos">,</span> <span class="pl-c1">5</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c1">^</span>

SyntaxError: <span class="pl-v">Unexpected</span> <span class="pl-s1">token</span> <span class="pl-s">')'</span>
<span class="pl-en">at</span> <span class="pl-s1">wrapSafe</span> <span class="pl-kos">(</span><span class="pl-s1">internal</span><span class="pl-c1">/</span><span class="pl-s1">modules</span><span class="pl-c1">/</span><span class="pl-s1">cjs</span><span class="pl-c1">/</span><span class="pl-s1">loader</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">1053</span>:<span class="pl-c1">16</span><span class="pl-kos">)</span>
<span class="pl-s1">at</span> <span class="pl-v">Module</span><span class="pl-kos">.</span><span class="pl-en">_compile</span> <span class="pl-kos">(</span><span class="pl-s1">internal</span><span class="pl-c1">/</span><span class="pl-s1">modules</span><span class="pl-c1">/</span><span class="pl-s1">cjs</span><span class="pl-c1">/</span><span class="pl-s1">loader</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">1101</span>:<span class="pl-c1">27</span><span class="pl-kos">)</span>
<span class="pl-s1">at</span> <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-c1">Module</span><span class="pl-kos">.</span><span class="pl-c1">_extensions</span><span class="pl-kos">.</span><span class="pl-kos">.</span><span class="pl-en">js</span> <span class="pl-kos">(</span><span class="pl-s1">internal</span><span class="pl-c1">/</span><span class="pl-s1">modules</span><span class="pl-c1">/</span><span class="pl-s1">cjs</span><span class="pl-c1">/</span><span class="pl-s1">loader</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">1157</span>:<span class="pl-c1">10</span><span class="pl-kos">)</span>
<span class="pl-s1">at</span> <span class="pl-v">Module</span><span class="pl-kos">.</span><span class="pl-en">load</span> <span class="pl-kos">(</span><span class="pl-s1">internal</span><span class="pl-c1">/</span><span class="pl-s1">modules</span><span class="pl-c1">/</span><span class="pl-s1">cjs</span><span class="pl-c1">/</span><span class="pl-s1">loader</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">985</span>:<span class="pl-c1">32</span><span class="pl-kos">)</span>
<span class="pl-s1">at</span> <span class="pl-v">Function</span><span class="pl-kos">.</span><span class="pl-c1">Module</span><span class="pl-kos">.</span><span class="pl-en">_load</span> <span class="pl-kos">(</span><span class="pl-s1">internal</span><span class="pl-c1">/</span><span class="pl-s1">modules</span><span class="pl-c1">/</span><span class="pl-s1">cjs</span><span class="pl-c1">/</span><span class="pl-s1">loader</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">878</span>:<span class="pl-c1">14</span><span class="pl-kos">)</span>
<span class="pl-s1">at</span> <span class="pl-v">Function</span><span class="pl-kos">.</span><span class="pl-c1">executeUserEntryPoint</span> <span class="pl-kos">[</span><span class="pl-s1">as</span> <span class="pl-s1">runMain</span><span class="pl-kos">]</span> <span class="pl-kos">(</span><span class="pl-s1">internal</span><span class="pl-c1">/</span><span class="pl-s1">modules</span><span class="pl-c1">/</span><span class="pl-s1">run_main</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">71</span>:<span class="pl-c1">12</span><span class="pl-kos">)</span>
<span class="pl-s1">at</span><span class="pl-kos"></span> <span class="pl-s1">internal</span><span class="pl-c1">/</span><span class="pl-s1">main</span><span class="pl-c1">/</span><span class="pl-s1">run_main_module</span><span class="pl-kos">.</span><span class="pl-c1">js</span>:<span class="pl-c1">17</span>:<span class="pl-c1">47</span></pre></div>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<p dir="auto">Issue is because of adding webpackPrefetch in below import</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import loadable from '@loadable/component';

const Component = loadable(
    () =&gt;
        import(
            /* webpackPrefetch: true */ /* webpackChunkName: &quot;compChunk&quot; */ '../component'
        ),
    { ssr: false }
);"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">loadable</span> <span class="pl-k">from</span> <span class="pl-s">'@loadable/component'</span><span class="pl-kos">;</span>

<span class="pl-k">const</span> <span class="pl-v">Component</span> <span class="pl-c1">=</span> <span class="pl-en">loadable</span><span class="pl-kos">(</span>
    <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span>
        <span class="pl-k">import</span><span class="pl-kos">(</span>
            <span class="pl-c">/* webpackPrefetch: true */</span> <span class="pl-c">/* webpackChunkName: "compChunk" */</span> <span class="pl-s">'../component'</span>
        <span class="pl-kos">)</span><span class="pl-kos">,</span>
    <span class="pl-kos">{</span> <span class="pl-c1">ssr</span>: <span class="pl-c1">false</span> <span class="pl-kos">}</span>
<span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>






<p dir="auto"><strong>What is the expected behavior?</strong></p>
<p dir="auto">Server should get start without any error with <strong>webpackPrefetch</strong> in dynamic import</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  5.38.0<br>
Node.js version:  12.18.4<br>
Operating System: Mac 10.14.6</p>
<p dir="auto"><strong>Do you want to request a <em>feature</em> or report a <em>bug</em>?</strong><br>
It's either a bug or the <a href="https://webpack.js.org/plugins/commons-chunk-plugin/" rel="nofollow">documentation</a> is not clear.</p>


<p dir="auto"><strong>What is the current behavior?</strong><br>
Trying to solve this <a href="http://stackoverflow.com/questions/43210152/webpack-2-splitting-libraries-vendor-and-app-into-different-files?noredirect=1#comment73503668_43210152" rel="nofollow">stackoverflow question</a>.<br>
I use <code class="notranslate">webpack.optimize.CommonsChunkPlugin</code> twice, but only first <code class="notranslate">minChunks</code> function is applied.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong><br>
Here is the example repo:<br>
<a href="https://github.com/PavelPolyakov/webpack-react-bundles/tree/feature/advanced-CommonsChunkPlugin">https://github.com/PavelPolyakov/webpack-react-bundles/tree/feature/advanced-CommonsChunkPlugin</a></p>
<p dir="auto"><strong>What is the expected behavior?</strong><br>
With <a href="https://github.com/PavelPolyakov/webpack-react-bundles/blob/feature/advanced-CommonsChunkPlugin/conf/webpack.production.config.js">this code</a>:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="plugins: [
        // put lodash and moment in one file
        new webpack.optimize.CommonsChunkPlugin({
            name: 'lodash+moment',
            minChunks: function (module) {
                let result = module.context &amp;&amp; _.reduce(['lodash', 'moment'], (result, record) =&gt; result || _(module.context).includes(`node_modules/${record}`), false);
                if (result) {
                    console.log('+++', module.context);
                }
                return result;
            }
        }),
        // put everything else in the other file
        new webpack.optimize.CommonsChunkPlugin({
            name: 'vendor',
            minChunks: function (module) {
                let result = module.context &amp;&amp; _(module.context).includes(`node_modules`) &amp;&amp; !_.reduce(['lodash', 'moment'], (result, record) =&gt; result || _(module.context).includes(`node_modules/${record}`), false);
                console.log('attempt', module.context);
                if (result) {
                    console.log('---', module.context);
                }
                return result;
            }
        })
    ]"><pre class="notranslate">plugins: <span class="pl-kos">[</span>
        <span class="pl-c">// put lodash and moment in one file</span>
        <span class="pl-k">new</span> <span class="pl-s1">webpack</span><span class="pl-kos">.</span><span class="pl-c1">optimize</span><span class="pl-kos">.</span><span class="pl-c1">CommonsChunkPlugin</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
            <span class="pl-c1">name</span>: <span class="pl-s">'lodash+moment'</span><span class="pl-kos">,</span>
            <span class="pl-en">minChunks</span>: <span class="pl-k">function</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-k">let</span> <span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-s1">module</span><span class="pl-kos">.</span><span class="pl-c1">context</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">_</span><span class="pl-kos">.</span><span class="pl-en">reduce</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-s">'lodash'</span><span class="pl-kos">,</span> <span class="pl-s">'moment'</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">result</span><span class="pl-kos">,</span> <span class="pl-s1">record</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">result</span> <span class="pl-c1">||</span> <span class="pl-en">_</span><span class="pl-kos">(</span><span class="pl-s1">module</span><span class="pl-kos">.</span><span class="pl-c1">context</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">includes</span><span class="pl-kos">(</span><span class="pl-s">`node_modules/<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">record</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-c1">false</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">result</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-s">'+++'</span><span class="pl-kos">,</span> <span class="pl-s1">module</span><span class="pl-kos">.</span><span class="pl-c1">context</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
                <span class="pl-kos">}</span>
                <span class="pl-k">return</span> <span class="pl-s1">result</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">// put everything else in the other file</span>
        <span class="pl-k">new</span> <span class="pl-s1">webpack</span><span class="pl-kos">.</span><span class="pl-c1">optimize</span><span class="pl-kos">.</span><span class="pl-c1">CommonsChunkPlugin</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
            <span class="pl-c1">name</span>: <span class="pl-s">'vendor'</span><span class="pl-kos">,</span>
            <span class="pl-en">minChunks</span>: <span class="pl-k">function</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-k">let</span> <span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-s1">module</span><span class="pl-kos">.</span><span class="pl-c1">context</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-en">_</span><span class="pl-kos">(</span><span class="pl-s1">module</span><span class="pl-kos">.</span><span class="pl-c1">context</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">includes</span><span class="pl-kos">(</span><span class="pl-s">`node_modules`</span><span class="pl-kos">)</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-c1">!</span><span class="pl-s1">_</span><span class="pl-kos">.</span><span class="pl-en">reduce</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-s">'lodash'</span><span class="pl-kos">,</span> <span class="pl-s">'moment'</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">result</span><span class="pl-kos">,</span> <span class="pl-s1">record</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">result</span> <span class="pl-c1">||</span> <span class="pl-en">_</span><span class="pl-kos">(</span><span class="pl-s1">module</span><span class="pl-kos">.</span><span class="pl-c1">context</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">includes</span><span class="pl-kos">(</span><span class="pl-s">`node_modules/<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">record</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-c1">false</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-s">'attempt'</span><span class="pl-kos">,</span> <span class="pl-s1">module</span><span class="pl-kos">.</span><span class="pl-c1">context</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">result</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-s">'---'</span><span class="pl-kos">,</span> <span class="pl-s1">module</span><span class="pl-kos">.</span><span class="pl-c1">context</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
                <span class="pl-kos">}</span>
                <span class="pl-k">return</span> <span class="pl-s1">result</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">I want to filter <code class="notranslate">lodash</code> and <code class="notranslate">moment</code> to one file and the other <code class="notranslate">node_modules</code> to the other.</p>
<p dir="auto">I also did another attempt, like the one from the documentation:<br>
<a href="https://github.com/webpack/webpack/tree/master/examples/multiple-commons-chunks">https://github.com/webpack/webpack/tree/master/examples/multiple-commons-chunks</a></p>
<p dir="auto">Here is the attempt, it doesn't work:<br>
<a href="https://github.com/PavelPolyakov/webpack-react-bundles/blob/feature/separate-entries/conf/webpack.production.config.js">https://github.com/PavelPolyakov/webpack-react-bundles/blob/feature/separate-entries/conf/webpack.production.config.js</a></p>
<p dir="auto">I would appreciate any suggestion how to solve my issue. PR into the example repository is appreciated the most :)</p>
<p dir="auto">Webpack version 2.2.1.</p>
<p dir="auto">Regards,</p>