Bug: NormalModule.dependencyTemplatesHashMap never gets updated
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
Webpack seems to produce bad output when doing incremental builds since https://github.com/webpack/webpack/commit/c1a02446acfd50f2992515e08d6fa6ea69d2eaef was merged (Webpack v3.3.0 and newer)
More specifically, the issue seems to be that dtHash
is always undefined
since there doesn’t seem to be any change in that commit to actually write to the “hash” key of NormalModule.dependencyTemplatesHashMap - the only change that is setting “hash” seems to be in the unrelated innerDependencyTemplates in ConcatenatedModule.
If the current behavior is a bug, please provide the steps to reproduce.
I was able to reproduce on an incremental build when modifying a file and then waiting for webpack dev server to reload.
After the reload the console will show “TypeError: _apolloClient2.default is not a constructor” (the first component referenced is from react-apollo) for a normally harmless import that is being used.
git bisect
clearly showed that https://github.com/webpack/webpack/commit/c1a02446acfd50f2992515e08d6fa6ea69d2eaef is at fault, and that going one commit before that doesn’t exhibit the buggy behavior.
Similarly, the following patch also makes things work, but thats just to show that the issue here really is that dtHash is undefined:
forbes:webpack lfittl$ git diff
diff --git a/lib/NormalModule.js b/lib/NormalModule.js
index eef44b73..3e1fcc0d 100644
--- a/lib/NormalModule.js
+++ b/lib/NormalModule.js
@@ -276,6 +276,7 @@ class NormalModule extends Module {
this.variables.length = 0;
this.blocks.length = 0;
this._cachedSource = null;
+ this._dependencyTemplatesHashMap = new Map();
// if we have an error mark module as failed and exit
if(err) {
@@ -308,7 +309,11 @@ class NormalModule extends Module {
}
getHashDigest(dependencyTemplates) {
- let dtHash = dependencyTemplatesHashMap.get("hash");
+ let dtId = this._dependencyTemplatesHashMap.get(dependencyTemplates);
+ if(dtId === undefined)
+ this._dependencyTemplatesHashMap.set(dependencyTemplates, dtId = this._dependencyTemplatesHashMap.size + 1);
+
+ let dtHash = dependencyTemplatesHashMap.get("hash") || dtId;
const hash = crypto.createHash("md5");
this.updateHash(hash);
hash.update(`${dtHash}`);
What is the expected behavior?
Imports should not error out after an incremental build
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
- Webpack v3.3.0 and newer (tested on master as well)
- macOS 10.12.6
- Node v8.2.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
dependencyTemplates
is a different instance for each Compiler run. The old code using_dependencyTemplatesHashMap
was broken because it disabled caching completely.So I guess the problem is somewhere else, but it would be great to have a repro repo to find it.
Issue was closed because of inactivity.
If you think this is still a valid issue, please file a new issue with additional information.