<p dir="auto">not sure if it's too early to file bugs regarding experimental features?</p>
<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong><br>
webpack library.type "module" generates commonjs syntax (module.exports/require) for node.js builtins (when target is node) and for any module specified as external(s).</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="export { version } from &quot;process&quot;;"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-kos">{</span> <span class="pl-s1">version</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"process"</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="export default {
  entry: {
    index: &quot;./index.js&quot;,
  },
  experiments: {
    outputModule: true,
  },
  // externals: ...
  output: {
    filename: &quot;[name].js&quot;,
    library: {
      type: &quot;module&quot;,
    },
  },
  target: &quot;node&quot;,
};"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">default</span> <span class="pl-kos">{</span>
  <span class="pl-c1">entry</span>: <span class="pl-kos">{</span>
    <span class="pl-c1">index</span>: <span class="pl-s">"./index.js"</span><span class="pl-kos">,</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-c1">experiments</span>: <span class="pl-kos">{</span>
    <span class="pl-c1">outputModule</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-c">// externals: ...</span>
  <span class="pl-c1">output</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">library</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">type</span>: <span class="pl-s">"module"</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-c1">target</span>: <span class="pl-s">"node"</span><span class="pl-kos">,</span>
<span class="pl-kos">}</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="/***/ &quot;process&quot;:
/*!**************************!*\
  !*** external &quot;process&quot; ***!
  \**************************/
/***/ ((module) =&gt; {

module.exports = require(&quot;process&quot;);;

/***/ })"><pre class="notranslate"><span class="pl-c">/***/</span> <span class="pl-s">"process"</span>:
<span class="pl-c">/*!**************************!*\</span>
<span class="pl-c">  !*** external "process" ***!</span>
<span class="pl-c">  \**************************/</span>
<span class="pl-c">/***/</span> <span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-s1">module</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>

<span class="pl-s1">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"process"</span><span class="pl-kos">)</span><span class="pl-kos">;</span><span class="pl-kos">;</span>

<span class="pl-c">/***/</span> <span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>






<p dir="auto"><strong>What is the expected behavior?</strong><br>
I'd imagine that node builtins have to be either required on top of the file (outer module scope) or possibly dynamically <strong>import()</strong> ed.</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  v5.22.0<br>
Node.js version: v15.12.0<br>
Operating System: macOS Big Sur<br>
Additional tools: n/a</p>
<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto">Getting errors after updating to 5.19.0</p>
<p dir="auto"><code class="notranslate">Uncaught ReferenceError: __webpack_require__ is not defined</code><br>
<code class="notranslate">Uncaught (in promise) TypeError: c(...).Z is not a function</code></p>
<p dir="auto">The compiled code is missing <code class="notranslate">__webpack_require__</code></p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<p dir="auto">Here's a very minimal setup that reproduces this bug.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// webpack.config.js
const path = require(&quot;path&quot;);

module.exports = {
  entry: {
    app: &quot;./src/app.js&quot;,
    home: {
      import: './src/home.js',
      dependOn: 'app' // removing this line fixes it
    }
  },
  output: {
    path: path.resolve(&quot;./dist&quot;),
  },
  optimization: {
    runtimeChunk: &quot;single&quot;,
  },
};"><pre class="notranslate"><span class="pl-c">// webpack.config.js</span>
<span class="pl-k">const</span> <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"path"</span><span class="pl-kos">)</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-kos">{</span>
  <span class="pl-c1">entry</span>: <span class="pl-kos">{</span>
    <span class="pl-c1">app</span>: <span class="pl-s">"./src/app.js"</span><span class="pl-kos">,</span>
    <span class="pl-c1">home</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">import</span>: <span class="pl-s">'./src/home.js'</span><span class="pl-kos">,</span>
      <span class="pl-c1">dependOn</span>: <span class="pl-s">'app'</span> <span class="pl-c">// removing this line fixes it</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">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-s">"./dist"</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">optimization</span>: <span class="pl-kos">{</span>
    <span class="pl-c1">runtimeChunk</span>: <span class="pl-s">"single"</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>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// src/app.js
import(&quot;./test.js&quot;);"><pre class="notranslate"><span class="pl-c">// src/app.js</span>
<span class="pl-k">import</span><span class="pl-kos">(</span><span class="pl-s">"./test.js"</span><span class="pl-kos">)</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="// src/log.js
export default function (msg) {
  console.log(msg);
}"><pre class="notranslate"><span class="pl-c">// src/log.js</span>
<span class="pl-k">export</span> <span class="pl-k">default</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">msg</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-s1">msg</span><span class="pl-kos">)</span><span class="pl-kos">;</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="// src/test.js
import log from &quot;./log&quot;;
log(&quot;Hi&quot;);"><pre class="notranslate"><span class="pl-c">// src/test.js</span>
<span class="pl-k">import</span> <span class="pl-s1">log</span> <span class="pl-k">from</span> <span class="pl-s">"./log"</span><span class="pl-kos">;</span>
<span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"Hi"</span><span class="pl-kos">)</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="// src/home.js
import log from &quot;./log&quot;;
log(&quot;Hi&quot;);"><pre class="notranslate"><span class="pl-c">// src/home.js</span>
<span class="pl-k">import</span> <span class="pl-s1">log</span> <span class="pl-k">from</span> <span class="pl-s">"./log"</span><span class="pl-kos">;</span>
<span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"Hi"</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;script src=&quot;runtime.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;home.js&quot;&gt;&lt;/script&gt;"><pre class="notranslate"><span class="pl-kos">&lt;</span><span class="pl-ent">script</span> <span class="pl-c1">src</span>="<span class="pl-s">runtime.js</span>"<span class="pl-kos">&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;</span><span class="pl-ent">script</span> <span class="pl-c1">src</span>="<span class="pl-s">app.js</span>"<span class="pl-kos">&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;</span><span class="pl-ent">script</span> <span class="pl-c1">src</span>="<span class="pl-s">home.js</span>"<span class="pl-kos">&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span></pre></div>






<p dir="auto"><strong>What is the expected behavior?</strong></p>
<p dir="auto">This error should not happen, it was working without errors on 5.18.0</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  5.19.0<br>
Node.js version: v15.7.0<br>
Operating System: macOS 11.2<br>
Additional tools:</p>