question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: NormalModule.dependencyTemplatesHashMap never gets updated

See original GitHub issue

Do 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:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sokracommented, Aug 14, 2017

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.

0reactions
webpack-botcommented, Mar 3, 2018

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

userguide.pdf - Gradle User Manual
Upgrading your build from Gradle 6.x to the latest. ... tasks, dependencies, plugins, and other configuration for that project.
Read more >
Gradle User Guide - gvSIG Association
Getting the insight into a particular dependency. Output of gradle -q webapp:dependencyInsight --dependency groovy --configuration compile.
Read more >
HashMap (Java Platform SE 8 ) - Oracle Help Center
This implementation provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among ...
Read more >
Create-React-App with TypeScript failing to compile after ...
I've created a new React app by running npx create-react-app@latest --typescript . and I've run the project using npm start and it all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found