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




<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto">When using dynamic imports with expressions together with <code class="notranslate">ContextReplacementPlugin</code> in order to limit the possible file matches, some module ids which should deterministic, are actually dependent on the project's location.<br>
Meaning two identical projects (code, dependencies, configuration etc..) built on the same machine have different build outputs based on their location on the filesystem.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<ul dir="auto">
<li>use dynamic imports with expessions
<ul dir="auto">
<li>ie: <strong>import(<code class="notranslate">../i18n/${locale}.json</code>)</strong>)</li>
</ul>
</li>
<li>configure Webpack to use <code class="notranslate">ContextReplacementPlugin</code> to limit which JSON files should be bundled
<ul dir="auto">
<li>ie: <code class="notranslate">new webpack.ContextReplacementPlugin(/i18n/, regExpForLocales)</code></li>
</ul>
</li>
<li>build the project for production</li>
<li>duplicate the project at another location on the filesystem at a different path root level
<ul dir="auto">
<li>ie: <code class="notranslate">/home/project</code> vs <code class="notranslate">/home/work/projects</code></li>
</ul>
</li>
<li>build the project for production at the new location</li>
<li>diff both output bundles, observe that both bundles are different, invalidating the project build's reproducibility</li>
</ul>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ diff -u context-a/dist/main.js folder-b/context-b/dist/main.js"><pre class="notranslate">$ diff -u context-a/dist/main.js folder-b/context-b/dist/main.js</pre></div>
<div class="highlight highlight-source-diff notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="--- context-a/dist/main.js	2022-01-10 14:52:49.395750091 +0100
+++ folder-b/context-b/dist/main.js	2022-01-10 14:52:52.143773687 +0100
@@ -4,7 +4,7 @@
     t,
     o,
     n = {
-      595: (e, r, t) =&gt; {
+      174: (e, r, t) =&gt; {
         var o = { &quot;./a.json&quot;: [359, 359], &quot;./b.json&quot;: [376, 376] };
         function n(e) {
           if (!t.o(o, e))
@@ -16,7 +16,7 @@
             n = r[0];
           return t.e(r[1]).then(() =&gt; t.t(n, 19));
         }
-        (n.keys = () =&gt; Object.keys(o)), (n.id = 595), (e.exports = n);
+        (n.keys = () =&gt; Object.keys(o)), (n.id = 174), (e.exports = n);
       },
     },
     i = {};
"><pre class="notranslate"><span class="pl-md">--- context-a/dist/main.js	2022-01-10 14:52:49.395750091 +0100</span>
<span class="pl-mi1">+++ folder-b/context-b/dist/main.js	2022-01-10 14:52:52.143773687 +0100</span>
<span class="pl-mdr">@@ -4,7 +4,7 @@</span>
     t,
     o,
     n = {
<span class="pl-md"><span class="pl-md">-</span>      595: (e, r, t) =&gt; {</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>      174: (e, r, t) =&gt; {</span>
         var o = { "./a.json": [359, 359], "./b.json": [376, 376] };
         function n(e) {
           if (!t.o(o, e))
<span class="pl-mdr">@@ -16,7 +16,7 @@</span>
             n = r[0];
           return t.e(r[1]).then(() =&gt; t.t(n, 19));
         }
<span class="pl-md"><span class="pl-md">-</span>        (n.keys = () =&gt; Object.keys(o)), (n.id = 595), (e.exports = n);</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>        (n.keys = () =&gt; Object.keys(o)), (n.id = 174), (e.exports = n);</span>
       },
     },
     i = {};
</pre></div>
<p dir="auto"><a href="https://github.com/ziir/webpack-repro-dynamic-import-context-replacement-deterministic-module-id">Minimal reproduction repository</a></p>






<p dir="auto"><strong>What is the expected behavior?</strong></p>
<ul dir="auto">
<li>both bundles should be identical irrelevant of their location on the filesystem</li>
</ul>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  <em>5.65.0</em><br>
Node.js version:  <em>14.18.1</em><br>
Operating System: <em>Linux Ubuntu 20.04.3 LTS</em><br>
Additional tools: <em>N/A</em></p>
<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong><br>
In my project, import jspdf.<br>
The origin source<br>
var f=[1,1.387039845,1.306562965,1.175875602,1,.785694958,.5411961,.275899379]<br>
After bundle,<br>
var f=[1,1.387039845,1.306562965,1.175875602,1,.7d0ffc958,.5411961,.275899379]</p>
<p dir="auto">7<strong>85694</strong>958 was changed to 7<strong>d0ffc</strong>958</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<p dir="auto">In RealContentHashPlugin source code</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const newContent = asset.content.replace(hashRegExp, hash =&gt;
	hashToNewHash.get(hash)
);
return new RawSource(newContent);"><pre class="notranslate"><code class="notranslate">const newContent = asset.content.replace(hashRegExp, hash =&gt;
	hashToNewHash.get(hash)
);
return new RawSource(newContent);
</code></pre></div>
<p dir="auto">When there is a bundle unfortunately with hash 85694</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="assets/xxx/css/XXXX.85694.css { immutable: true, contenthash: '85694' }"><pre class="notranslate"><code class="notranslate">assets/xxx/css/XXXX.85694.css { immutable: true, contenthash: '85694' }
</code></pre></div>
<p dir="auto">Then<br>
hashRegExp has value contains 85694<br>
/---|85694|dcf17|----/g<br>
It cause<br>
.785694958 to be replaced to .7d0ffc958. Javascript load error</p>






<p dir="auto"><strong>What is the expected behavior?</strong><br>
Don't change original source behavior</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  5.36.1<br>
Node.js version: v14.17.6<br>
Operating System:  MacOS 11.4<br>
Additional tools:</p>