<h1 dir="auto">Bug report</h1>
<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto">Since <code class="notranslate">v4.20.0</code> defining an <code class="notranslate">output.library</code> as an Array results in <code class="notranslate">var = undefined</code> without a <code class="notranslate">output.libraryTarget</code>. Also using values of <code class="notranslate">"this"</code> or <code class="notranslate">"window</code> result in similar behavior when <code class="notranslate">output.library</code> is an Array.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// webpack.config.js

entry: {
  main: `./src/main.js`
},
output: {
  library: [ 'BLEEP', 'bloop' ],
  libraryExport: 'default',
  path: '/dist/',
  filename: '[name].js',
  publicPath: '/' 
}"><pre class="notranslate"><span class="pl-c">// webpack.config.js</span>

entry: <span class="pl-kos">{</span>
  <span class="pl-c1">main</span>: <span class="pl-s">`./src/main.js`</span>
<span class="pl-kos">}</span><span class="pl-kos">,</span>
<span class="pl-s1">output</span>: <span class="pl-kos">{</span>
  <span class="pl-c1">library</span>: <span class="pl-kos">[</span> <span class="pl-s">'BLEEP'</span><span class="pl-kos">,</span> <span class="pl-s">'bloop'</span> <span class="pl-kos">]</span><span class="pl-kos">,</span>
  <span class="pl-c1">libraryExport</span>: <span class="pl-s">'default'</span><span class="pl-kos">,</span>
  <span class="pl-c1">path</span>: <span class="pl-s">'/dist/'</span><span class="pl-kos">,</span>
  <span class="pl-c1">filename</span>: <span class="pl-s">'[name].js'</span><span class="pl-kos">,</span>
  <span class="pl-c1">publicPath</span>: <span class="pl-s">'/'</span> 
<span class="pl-kos">}</span></pre></div>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// main.js

export default () =&gt; {
  console.log('main bundle');
}"><pre class="notranslate"><span class="pl-c">// main.js</span>

<span class="pl-k">export</span> <span class="pl-k">default</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-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'main bundle'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">results in</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var undefined =
/******/ (function(modules) { // webpackBootstrap"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">undefined</span> <span class="pl-c1">=</span>
<span class="pl-c">/******/</span> <span class="pl-kos">(</span><span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">modules</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-c">// webpackBootstrap</span></pre></div>
<p dir="auto">if I add <code class="notranslate">output.libraryTarget = "umd"</code> I get a workable result but since I know this library is only consumed directly from the <code class="notranslate">window</code> it seems like adding extra cruft</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' &amp;&amp; typeof module === 'object')
		module.exports = factory();
	else if(typeof define === 'function' &amp;&amp; define.amd)
		define([], factory);
	else if(typeof exports === 'object')
		exports[&quot;main&quot;] = factory();
	else
		root[&quot;BLEEP&quot;] = root[&quot;BLEEP&quot;] || {}, root[&quot;BLEEP&quot;][&quot;bloop&quot;] = factory();
})(window, function() {"><pre class="notranslate"><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-en">webpackUniversalModuleDefinition</span><span class="pl-kos">(</span><span class="pl-s1">root</span><span class="pl-kos">,</span> <span class="pl-s1">factory</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-k">typeof</span> <span class="pl-s1">exports</span> <span class="pl-c1">===</span> <span class="pl-s">'object'</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-k">typeof</span> <span class="pl-smi">module</span> <span class="pl-c1">===</span> <span class="pl-s">'object'</span><span class="pl-kos">)</span>
		<span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-s1">factory</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-k">typeof</span> <span class="pl-s1">define</span> <span class="pl-c1">===</span> <span class="pl-s">'function'</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">define</span><span class="pl-kos">.</span><span class="pl-c1">amd</span><span class="pl-kos">)</span>
		<span class="pl-en">define</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">factory</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-k">typeof</span> <span class="pl-s1">exports</span> <span class="pl-c1">===</span> <span class="pl-s">'object'</span><span class="pl-kos">)</span>
		<span class="pl-s1">exports</span><span class="pl-kos">[</span><span class="pl-s">"main"</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">factory</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-s1">root</span><span class="pl-kos">[</span><span class="pl-s">"BLEEP"</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">root</span><span class="pl-kos">[</span><span class="pl-s">"BLEEP"</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-s1">root</span><span class="pl-kos">[</span><span class="pl-s">"BLEEP"</span><span class="pl-kos">]</span><span class="pl-kos">[</span><span class="pl-s">"bloop"</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">factory</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-smi">window</span><span class="pl-kos">,</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span></pre></div>
<p dir="auto">Specifying an <code class="notranslate">output.libraryTarget = "window"</code> also fails</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="window[undefined] =
/******/ (function(modules) { // webpackBootstrap"><pre class="notranslate"><span class="pl-smi">window</span><span class="pl-kos">[</span><span class="pl-c1">undefined</span><span class="pl-kos">]</span> <span class="pl-c1">=</span>
<span class="pl-c">/******/</span> <span class="pl-kos">(</span><span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">modules</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-c">// webpackBootstrap</span></pre></div>
<p dir="auto"><strong>What is the expected behavior?</strong><br>
prior to <code class="notranslate">v4.20.0</code> the generated bundle would contain</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var BLEEP = typeof BLEEP === &quot;object&quot; ? BLEEP : {}; BLEEP[&quot;bloop&quot;] =
/******/ (function(modules) { // webpackBootstrap"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-c1">BLEEP</span> <span class="pl-c1">=</span> <span class="pl-k">typeof</span> <span class="pl-c1">BLEEP</span> <span class="pl-c1">===</span> <span class="pl-s">"object"</span> ? <span class="pl-c1">BLEEP</span> : <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">;</span> <span class="pl-c1">BLEEP</span><span class="pl-kos">[</span><span class="pl-s">"bloop"</span><span class="pl-kos">]</span> <span class="pl-c1">=</span>
<span class="pl-c">/******/</span> <span class="pl-kos">(</span><span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">modules</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-c">// webpackBootstrap</span></pre></div>
<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  <code class="notranslate">&gt;=4.20.0</code><br>
Node.js version: <code class="notranslate">8.10.0</code><br>
Operating System: OSX Sierra</p>
<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto">Combination of <code class="notranslate">output.libraryTarget: 'window'</code> and <code class="notranslate">output.library: string[]</code> gives an erroneous rusult:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="window[undefined] = 
..."><pre class="notranslate"><code class="notranslate">window[undefined] = 
...
</code></pre></div>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const config = {
  mode: 'development',
  entry: {
    templates: './tpl.js'
  },
  output: {
    path: `${__dirname}/build`,
    filename: '[name].js',
    library: ['MyLib', '[name]'],
    libraryTarget: 'window'
  }
};"><pre class="notranslate"><code class="notranslate">const config = {
  mode: 'development',
  entry: {
    templates: './tpl.js'
  },
  output: {
    path: `${__dirname}/build`,
    filename: '[name].js',
    library: ['MyLib', '[name]'],
    libraryTarget: 'window'
  }
};
</code></pre></div>






<p dir="auto"><strong>What is the expected behavior?</strong></p>
<p dir="auto">This config should generate output like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="window[&quot;MyLib&quot;] = window[&quot;MyLib&quot;] || {}; window[&quot;MyLib&quot;][&quot;templates&quot;] =
..."><pre class="notranslate"><code class="notranslate">window["MyLib"] = window["MyLib"] || {}; window["MyLib"]["templates"] =
...
</code></pre></div>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  4.20.2<br>
Node.js version: v10.7.0<br>
Operating System: win10</p>
<p dir="auto">Looks like the issue is here: <a href="https://github.com/webpack/webpack/blob/master/lib/LibraryTemplatePlugin.js#L28-L29">https://github.com/webpack/webpack/blob/master/lib/LibraryTemplatePlugin.js#L28-L29</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const accessorAccess = (base, accessor, umdProperty, joinWith = &quot;; &quot;) =&gt; {
	const normalizedAccessor =
		typeof accessor === &quot;object&quot; ? accessor[umdProperty] : accessor;
	const accessors = Array.isArray(normalizedAccessor)
		? normalizedAccessor
		: [normalizedAccessor];"><pre class="notranslate"><code class="notranslate">const accessorAccess = (base, accessor, umdProperty, joinWith = "; ") =&gt; {
	const normalizedAccessor =
		typeof accessor === "object" ? accessor[umdProperty] : accessor;
	const accessors = Array.isArray(normalizedAccessor)
		? normalizedAccessor
		: [normalizedAccessor];
</code></pre></div>
<p dir="auto">if <code class="notranslate">accessor</code> parameter is an array it passes the <code class="notranslate">typeof accessor === "object"</code> condition anyway (thanks JS).</p>
<p dir="auto">PS.<br>
Sorry for not sumbiting a PR - I am not so familar with github processes.</p>