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




<p dir="auto">As per discussion on <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1098263961" data-permission-text="Title is private" data-url="https://github.com/webpack/webpack/issues/15143" data-hovercard-type="issue" data-hovercard-url="/webpack/webpack/issues/15143/hovercard" href="https://github.com/webpack/webpack/issues/15143">#15143</a></p>
<blockquote>
<p dir="auto">I'm building a react component library, so I declare react and react-dom as externals. I'm using webpack to build our library as a module, with experiments.outputModule = true, output.environment.module = true, and output.library.type = 'module'.</p>
</blockquote>
<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto">When I import my component into a create-react-app project, I get this crash:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Uncaught TypeError: __webpack_require__.r is not a function
    at Object../node_modules/webpack-external-repro-case/es/index.js (warning.js:62)
    at __webpack_require__ (bootstrap:856)
    at fn (bootstrap:150)
    at Module.&lt;anonymous&gt; (index.module.css?438e:82)"><pre class="notranslate"><code class="notranslate">Uncaught TypeError: __webpack_require__.r is not a function
    at Object../node_modules/webpack-external-repro-case/es/index.js (warning.js:62)
    at __webpack_require__ (bootstrap:856)
    at fn (bootstrap:150)
    at Module.&lt;anonymous&gt; (index.module.css?438e:82)
</code></pre></div>
<p dir="auto">When I switch optimization.minimize to true, my component can be imported successfully.</p>
<p dir="auto">On the previous issue, there was some discussion of external type (<code class="notranslate">module</code> vs <code class="notranslate">commonjs-module</code>). I've confirmed this occurs with both externalTypes.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong><br>
Reproduction repo (using the <code class="notranslate">minification-bug</code> branch): <a href="https://github.com/MustafaHaddara/webpack-external-repro-case/tree/minification-bug">https://github.com/MustafaHaddara/webpack-external-repro-case/tree/minification-bug</a></p>
<p dir="auto">(I used <a href="https://www.npmjs.com/package/yalc" rel="nofollow">yalc</a> to link but <code class="notranslate">npm | yarn link</code> probably works too)</p>
<p dir="auto">Turn minification on and the component is imported successfully.</p>






<p dir="auto"><strong>What is the expected behavior?</strong><br>
non-minified code should behave the same as minified code.</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  5.65.0 to build the component library, client is using <code class="notranslate">webpack@4.44.2</code> via <code class="notranslate">react-scripts@4.0.3</code><br>
Node.js version: 14<br>
Operating System:<br>
Additional tools:</p>
<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto">Building a project in <strong>production mode</strong> using webpack5 results in a <code class="notranslate">mod is not defined</code> error at runtime.</p>
<p dir="auto">If you build with development mode, no errors will occur at runtime.  In webpack4 this error does not occur when building in production mode.</p>
<p dir="auto">Also, when building with webpack4, there are no deprecation warnings.</p>
<p dir="auto">So I think this is a bug in webpack5.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/4439005/73892003-021fa780-48b9-11ea-9c4d-6fcc498fa60e.png"><img src="https://user-images.githubusercontent.com/4439005/73892003-021fa780-48b9-11ea-9c4d-6fcc498fa60e.png" alt="AAA1139D-F2EF-486C-81CF-DF810A18F7A5" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<p dir="auto">I haven't created a minimal reproducible repository yet, but here is the actual my project config.</p>
<p dir="auto"><a href="https://github.com/syuilo/misskey/blob/develop/webpack.config.ts">https://github.com/syuilo/misskey/blob/develop/webpack.config.ts</a></p>






<p dir="auto"><strong>What is the expected behavior?</strong></p>
<p dir="auto">No runtime error</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  5.0.0-beta.13<br>
Node.js version: 13.7.0<br>
Operating System: Windows10<br>
Additional tools:</p>