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




<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto">When compiling typescript using ts-loader with webpack, the <code class="notranslate">library</code> variable is not hoisted to the global level, thereby not exposing it at all.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>

<p dir="auto">MWE at <a href="https://github.com/retorquere/webpack-mwe">https://github.com/retorquere/webpack-mwe</a></p>
<p dir="auto">With webpack 5.21.2, <code class="notranslate">var MyModule =</code> is declared at the top of the webpacked output; with 5.24.4, it is declared inside the IIFE and thus not available at the global level.</p>





<p dir="auto"><strong>What is the expected behavior?</strong></p>
<p dir="auto">that the variable in <code class="notranslate">output.library</code> is declared in a way that it is available at the global level</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version: 5.21.2 vs 5.24.4<br>
Node.js version: v15.5.0<br>
Operating System: MacOS big sur<br>
Additional tools: none</p>
<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Module build failed (from /home/circleci/project/node_modules/mini-css-extract-plugin/dist/loader.js):
  TypeError: Cannot read property 'identifier' of null
      at text.map.line (/home/circleci/project/node_modules/mini-css-extract-plugin/dist/loader.js:160:32)
      at Array.map (&lt;anonymous&gt;)
      at childCompiler.runAsChild (/home/circleci/project/node_modules/mini-css-extract-plugin/dist/loader.js:157:21)
      at compile (/home/circleci/project/node_modules/webpack/lib/Compiler.js:306:11)
      at hooks.afterCompile.callAsync.err (/home/circleci/project/node_modules/webpack/lib/Compiler.js:631:15)
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/circleci/project/node_modules/tapable/lib/HookCodeFactory.js:32:10), &lt;anonymous&gt;:24:1)
      at AsyncSeriesHook.lazyCompileHook (/home/circleci/project/node_modules/tapable/lib/Hook.js:154:20)
      at compilation.seal.err (/home/circleci/project/node_modules/webpack/lib/Compiler.js:628:31)
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/circleci/project/node_modules/tapable/lib/HookCodeFactory.js:32:10), &lt;anonymous&gt;:6:1)
      at AsyncSeriesHook.lazyCompileHook (/home/circleci/project/node_modules/tapable/lib/Hook.js:154:20)
      at hooks.optimizeAssets.callAsync.err (/home/circleci/project/node_modules/webpack/lib/Compilation.js:1329:35)
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/circleci/project/node_modules/tapable/lib/HookCodeFactory.js:32:10), &lt;anonymous&gt;:6:1)
      at AsyncSeriesHook.lazyCompileHook (/home/circleci/project/node_modules/tapable/lib/Hook.js:154:20)
      at hooks.optimizeChunkAssets.callAsync.err (/home/circleci/project/node_modules/webpack/lib/Compilation.js:1320:32)
      at _promise1.then._result1 (eval at create (/home/circleci/project/node_modules/tapable/lib/HookCodeFactory.js:32:10), &lt;anonymous&gt;:18:1)
      at &lt;anonymous&gt;
   @ ./style/index.ts 1:0-29
   @ multi ./common/errorTracker ./common/polyfills ./style ./frames/about"><pre class="notranslate"><code class="notranslate">Module build failed (from /home/circleci/project/node_modules/mini-css-extract-plugin/dist/loader.js):
  TypeError: Cannot read property 'identifier' of null
      at text.map.line (/home/circleci/project/node_modules/mini-css-extract-plugin/dist/loader.js:160:32)
      at Array.map (&lt;anonymous&gt;)
      at childCompiler.runAsChild (/home/circleci/project/node_modules/mini-css-extract-plugin/dist/loader.js:157:21)
      at compile (/home/circleci/project/node_modules/webpack/lib/Compiler.js:306:11)
      at hooks.afterCompile.callAsync.err (/home/circleci/project/node_modules/webpack/lib/Compiler.js:631:15)
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/circleci/project/node_modules/tapable/lib/HookCodeFactory.js:32:10), &lt;anonymous&gt;:24:1)
      at AsyncSeriesHook.lazyCompileHook (/home/circleci/project/node_modules/tapable/lib/Hook.js:154:20)
      at compilation.seal.err (/home/circleci/project/node_modules/webpack/lib/Compiler.js:628:31)
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/circleci/project/node_modules/tapable/lib/HookCodeFactory.js:32:10), &lt;anonymous&gt;:6:1)
      at AsyncSeriesHook.lazyCompileHook (/home/circleci/project/node_modules/tapable/lib/Hook.js:154:20)
      at hooks.optimizeAssets.callAsync.err (/home/circleci/project/node_modules/webpack/lib/Compilation.js:1329:35)
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/circleci/project/node_modules/tapable/lib/HookCodeFactory.js:32:10), &lt;anonymous&gt;:6:1)
      at AsyncSeriesHook.lazyCompileHook (/home/circleci/project/node_modules/tapable/lib/Hook.js:154:20)
      at hooks.optimizeChunkAssets.callAsync.err (/home/circleci/project/node_modules/webpack/lib/Compilation.js:1320:32)
      at _promise1.then._result1 (eval at create (/home/circleci/project/node_modules/tapable/lib/HookCodeFactory.js:32:10), &lt;anonymous&gt;:18:1)
      at &lt;anonymous&gt;
   @ ./style/index.ts 1:0-29
   @ multi ./common/errorTracker ./common/polyfills ./style ./frames/about
</code></pre></div>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<p dir="auto">My configuration is huge. I'd be happy to try and narrow down a minimal repro if necessary, but I hope that the error would be obvious given that this is a regression in a minor release. If it's not, just let me know.</p>






<p dir="auto"><strong>What is the expected behavior?</strong></p>
<p dir="auto">There should be no error during build.</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  4.32.0<br>
Node.js version: 8.9.0<br>
Operating System: macOS 10.14.5<br>
Additional tools: mini-css-extract-plugin 0.4.4</p>