<p dir="auto"><strong>Do you want to request a <em>feature</em> or report a <em>bug</em>?</strong><br>
Feature</p>


<p dir="auto"><strong>What is the current behavior?</strong></p>
<h3 dir="auto">Class hierarchy</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            Main (entry, common chunk)
           /    \
     ClassA      ClassB
       \          \
        \          ClassC
         \         /
       ReusableComponent"><pre class="notranslate"><code class="notranslate">            Main (entry, common chunk)
           /    \
     ClassA      ClassB
       \          \
        \          ClassC
         \         /
       ReusableComponent
</code></pre></div>
<p dir="auto">Main require ClassA and ClassB using require.ensure().<br>
ClassB require ClassC using require.ensure().<br>
ClassA and ClassC require ReusableComponent using simple require().</p>
<p dir="auto">
Finaly webpack emits following chunks:
</p><ul dir="auto">
<li>0.js - contains ClassA, <b>ReusableComponent</b></li>
<li>1.js - contains ClassB</li>
<li>2.js - contains ClassC, <b>ReusableComponent</b></li>
<li>main.js - contains Main class</li>
</ul>
<p dir="auto"></p>
<h3 dir="auto">Problem</h3>
<p dir="auto">I try to configure CommonsChunkPlugin to move ReusableClass to main chunk in order to remove code duplication.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="new webpack.optimize.CommonsChunkPlugin({
            name: 'main',
            minChunks: 2,
            children: true
        })"><pre class="notranslate"><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">'main'</span><span class="pl-kos">,</span>
            <span class="pl-c1">minChunks</span>: <span class="pl-c1">2</span><span class="pl-kos">,</span>
            <span class="pl-c1">children</span>: <span class="pl-c1">true</span>
        <span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">And webpack does not do this.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong><br>
repo: <a href="https://github.com/rasentry/webpack-chunks">https://github.com/rasentry/webpack-chunks</a></p>



<p dir="auto"><strong>What is the expected behavior?</strong><br>
ReusableCompoent class has to move to chunk main.</p>
<p dir="auto"><strong>Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.</strong><br>
Node.js 7.2.1<br>
Windows 10</p>
<h1 dir="auto">Bug report</h1>
<p dir="auto"><g-emoji class="g-emoji" alias="arrow_forward" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/25b6.png">▶️</g-emoji> You can try this repo to reproduce the bug: <a href="https://github.com/jaguilar87/webpack-issue-8099">https://github.com/jaguilar87/webpack-issue-8099</a></p>




<p dir="auto"><strong>What is the current behavior?</strong><br>
Since <code class="notranslate">4.20.0</code> I am unable to build using nested output.library:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
       entry: {
            a: path.resolve(__dirname,  'a.js'),
            b: path.resolve(__dirname, 'b.js'),
       },
       output: {
            jsonpFunction: `webpackJsonp__[name]`,
            library: ['globalVariable', '[name]'],
            filename: `[name]--[chunkhash].js`,
            path: path.resolve(__dirname, 'dist'),
            publicPath: '/',
        },
..."><pre class="notranslate"><span class="pl-kos">{</span>
       <span class="pl-c1">entry</span>: <span class="pl-kos">{</span>
            <span class="pl-c1">a</span>: <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">resolve</span><span class="pl-kos">(</span><span class="pl-s1">__dirname</span><span class="pl-kos">,</span>  <span class="pl-s">'a.js'</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
            <span class="pl-c1">b</span>: <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">resolve</span><span class="pl-kos">(</span><span class="pl-s1">__dirname</span><span class="pl-kos">,</span> <span class="pl-s">'b.js'</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">output</span>: <span class="pl-kos">{</span>
            <span class="pl-c1">jsonpFunction</span>: <span class="pl-s">`webpackJsonp__[name]`</span><span class="pl-kos">,</span>
            <span class="pl-c1">library</span>: <span class="pl-kos">[</span><span class="pl-s">'globalVariable'</span><span class="pl-kos">,</span> <span class="pl-s">'[name]'</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
            <span class="pl-c1">filename</span>: <span class="pl-s">`[name]--[chunkhash].js`</span><span class="pl-kos">,</span>
            <span class="pl-c1">path</span>: <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">resolve</span><span class="pl-kos">(</span><span class="pl-s1">__dirname</span><span class="pl-kos">,</span> <span class="pl-s">'dist'</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
            <span class="pl-c1">publicPath</span>: <span class="pl-s">'/'</span><span class="pl-kos">,</span>
        <span class="pl-kos">}</span><span class="pl-kos">,</span>
...</pre></div>
<p dir="auto">The output file starts with:<br>
<code class="notranslate">var undefined = ...</code></p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong><br>
Use the previous configuration and try to build a package.</p>






<p dir="auto"><strong>What is the expected behavior?</strong><br>
The output file should start with:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var globalVariable = typeof globalVariable === &quot;object&quot; ? globalVariable : {}; globalVariable[&quot;a&quot;] = ..."><pre class="notranslate"><code class="notranslate">var globalVariable = typeof globalVariable === "object" ? globalVariable : {}; globalVariable["a"] = ...
</code></pre></div>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  4.20.0-4.20.2<br>
Node.js version:  v9.6.1<br>
Operating System: Mac OS High Sierra</p>