<p dir="auto">I am webpacking the <a href="https://www.npmjs.org/package/cheerio" rel="nofollow">cheerio</a> library and hit an error in its index.js:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ERROR in ./~/cheerio/index.js
Module not found: Error: Cannot resolve file or directory ./package in MYPROJECT\node_modules\cheerio.
 @ ./~/cheerio/index.js 13:18-38"><pre class="notranslate"><code class="notranslate">ERROR in ./~/cheerio/index.js
Module not found: Error: Cannot resolve file or directory ./package in MYPROJECT\node_modules\cheerio.
 @ ./~/cheerio/index.js 13:18-38
</code></pre></div>
<p dir="auto">The code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="exports.version = require('./package').version;"><pre class="notranslate"><span class="pl-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">version</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'./package'</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">version</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">It's obviously just trying to load package.json from the same directory.  The Node <a href="http://nodejs.org/api/modules.html" rel="nofollow">Modules documentation</a> states:</p>
<blockquote>
<p dir="auto">If the exact filename is not found, then node will attempt to load the required filename with the added extension of .js, .json, and then .node.</p>
</blockquote>
<p dir="auto">So, if we expect that npm packages are going to make use of this with vanilla 'require,' I think webpack should make the json loader default.  I believe that would mean changing:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="options.resolve.extensions = [&quot;&quot;, &quot;.node&quot;, &quot;.er.js&quot;, &quot;.js&quot;];"><pre class="notranslate"><span class="pl-s1">options</span><span class="pl-kos">.</span><span class="pl-c1">resolve</span><span class="pl-kos">.</span><span class="pl-c1">extensions</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-s">""</span><span class="pl-kos">,</span> <span class="pl-s">".node"</span><span class="pl-kos">,</span> <span class="pl-s">".er.js"</span><span class="pl-kos">,</span> <span class="pl-s">".js"</span><span class="pl-kos">]</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">in <a href="https://github.com/webpack/enhanced-require/blob/master/lib/require.js">https://github.com/webpack/enhanced-require/blob/master/lib/require.js</a></p>
<p dir="auto">to:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="options.resolve.extensions = [&quot;&quot;, &quot;.node&quot;, &quot;.er.js&quot;, &quot;.js&quot;, &quot;.json&quot;];"><pre class="notranslate"><span class="pl-s1">options</span><span class="pl-kos">.</span><span class="pl-c1">resolve</span><span class="pl-kos">.</span><span class="pl-c1">extensions</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-s">""</span><span class="pl-kos">,</span> <span class="pl-s">".node"</span><span class="pl-kos">,</span> <span class="pl-s">".er.js"</span><span class="pl-kos">,</span> <span class="pl-s">".js"</span><span class="pl-kos">,</span> <span class="pl-s">".json"</span><span class="pl-kos">]</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Right?</p>
<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong><br>
i am not sure whether this is webpack-dev-server issue or webpack or something else, however after 1st hot reload happens there is a constant error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="jsonp chunk loading:103 Uncaught TypeError: Cannot read property 'push' of undefined
    at self.webpackHotUpdatePACKAGEJSONNAME (jsonp chunk loading:103)"><pre class="notranslate"><code class="notranslate">jsonp chunk loading:103 Uncaught TypeError: Cannot read property 'push' of undefined
    at self.webpackHotUpdatePACKAGEJSONNAME (jsonp chunk loading:103)
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="self[&quot;webpackHotUpdatePACKAGEJSONNAME&quot;] = (chunkId, moreModules, runtime) =&gt; {
	for(var moduleId in moreModules) {
		if(__webpack_require__.o(moreModules, moduleId)) {
			currentUpdate[moduleId] = moreModules[moduleId];
			if(currentUpdatedModulesList) currentUpdatedModulesList.push(moduleId);
		}
	}
	if(runtime) currentUpdateRuntime.push(runtime); // error happens here
	if(waitingUpdateResolves[chunkId]) {
		waitingUpdateResolves[chunkId]();
		waitingUpdateResolves[chunkId] = undefined;
	}
};"><pre class="notranslate"><code class="notranslate">self["webpackHotUpdatePACKAGEJSONNAME"] = (chunkId, moreModules, runtime) =&gt; {
	for(var moduleId in moreModules) {
		if(__webpack_require__.o(moreModules, moduleId)) {
			currentUpdate[moduleId] = moreModules[moduleId];
			if(currentUpdatedModulesList) currentUpdatedModulesList.push(moduleId);
		}
	}
	if(runtime) currentUpdateRuntime.push(runtime); // error happens here
	if(waitingUpdateResolves[chunkId]) {
		waitingUpdateResolves[chunkId]();
		waitingUpdateResolves[chunkId] = undefined;
	}
};
</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">launch dev-server with hot:true</p>






<p dir="auto"><strong>What is the expected behavior?</strong><br>
does not happen in webpack@4<br>
i think that the issue is that this variable <code class="notranslate">currentUpdateRuntime</code> is accessed before it is initialized in:<br>
<code class="notranslate">__webpack_require__.hmrI.jsonp</code><br>
or<br>
<code class="notranslate">__webpack_require__.hmrC.jsonp</code></p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  5.1.0<br>
Node.js version: v12.18.0<br>
Operating System: Windows 10<br>
Additional tools:<br>
webpack-devs-server@latest</p>