-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Webpack 4 chunkhash/contenthash can vary between builds #7179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
- const outputFilename = dev || ci ? '[name].bundle.js' : '[name].[chunkhash].bundle.js';
+ const outputFilename = dev || ci ? '[name].bundle.js' : '[name].[contenthash].bundle.js'; TLDR: Use
|
Also don't forget to set the const output = {
filename: dev || ci ? '[name].bundle.js' : '[name].[contenthash].bundle.js',
chunkFilename: dev || ci ? '[name].chunk.js' : '[name].[contenthash].chunk.js'
} |
I changed it to contenthash, but I still get different hashes and they have the same content. I even took out the sourcemap output to make sure they are exactly the same. |
Experiencing the same issue, did you resolve it? EDIT: This plugin fixed my issue: |
@mikeyoon can you create minimum reproducible test repo? |
@evilebottnawi I tried, but wasn't able to narrow it down because I don't know what causes the issue or how the logic works. |
@mikeyoon can we close issue? if problem again appear we can reopen |
The issue has already been closed earlier, although it definitely still happens to me and I have chosen not to upgrade to Webpack 4 because of it. I don't really care too much at this point as v3 still works for us. |
it happens for me too and I do use |
I also have this issue with chunkhash but I am seeing a pattern:
|
Probably the hash is different because it's based on module IDs that are generated during the build. |
This section of the docs might be relevant.
|
I have HashedModuleIdsPlugin enabled, so there is probably some other factor. |
@mikeyoon , try also to enable NamedChunksPlugin (otherwise your chunks will get incremental ids as well as the modules) |
Didn't work with [contenthash] or [chunkhash] unfortunately. There's definitely something with our codebase that's triggering the issue. Not all of our chunks have inconsistent hashes. |
FYI I think plugins and loaders ( |
Update: from what I've noticed in the recent weeks, the issue actually happens also for some new chunks in our project that are not loaded via On my machine, for a given git revision, It seems that the source of this is some internal webpack global build state, and that |
@mikeyoon have you solved this problem ? |
Please create minimum reproducible test repo |
I have not looked at the issue since I posted about it last time. I also haven't had a chance to try out the latest major release either. We're still just using v3.x for now. |
Having the same issue on webpack 4, both with contenthash and chunkhash. If I find some time I will make a minimum repo. Shall the ticket be reopened ? |
As mentioned in the below link, [chunkhash] is unstable. webpack/webpack#7179 (comment) To ensure that every bundled files have consistent hash names based on it's contents, use [contenthash] instead of [chunkhash].
As mentioned in the below link, [chunkhash] is unstable. webpack/webpack#7179 (comment) To ensure that every bundled files have consistent hash names based on it's contents, use [contenthash] instead of [chunkhash].
We are seeing this problem too. Unfortunately, it's inconsistent and the codebase is private. Could it have something to do with running 10+ webpack commands simultaneously in different threads? (We are building a mono repo managed by rush. My assigned task is to determine why this is inconsistent, and to fix it, so any help you can provide would be much appreciated. Thanks. |
Same issue here. We do async imports and because of this we can't run the app on multiple machines because the code is built separately on each machine so generated files names are not the same on all the machines. |
I should have come back and posted an update. Short answer, Webpack's hashing algorithm is deterministic. But the content being sent to it may not be. I discovered a whole slew of issues:
I found the easiest way to debug this issue was to override the webpack hashing algorithm and add a little script to detect for my local absolute path. Here is approximately what I used: And then in webpack config: {
...
output: {
hashFunction: HashFunction,
...
}
} |
@halfnibble can you create minimum reproducible test repo, maybe we can fix some cases on webpack side |
@evilebottnawi As far as I can tell, there is absolutely nothing wrong with webpack's hashing algorithm. The problem lies in certain npm packages and webpack loaders. None of the problems I encountered were in code from the webpack organization. I don't know if it would be worthwhile to create a content hash debug feature like the one we developed to pin point the packages and loaders causing problems. |
@halfnibble thanks for feedback, yep, some loaders/plugins emit assets with absolute path, better open issues in repos with loaders/plugins |
@halfnibble re: #7179 (comment) fantastic comment, thanks to it I revisited the topic and found that it was indeed The info about not using absolute paths is documented in "writing a loader" doc: https://webpack.js.org/contribute/writing-a-loader/#absolute-paths |
As mentioned in the below link, [chunkhash] is unstable. webpack/webpack#7179 (comment) To ensure that every bundled files have consistent hash names based on it's contents, use [contenthash] instead of [chunkhash].
As mentioned in the below link, [chunkhash] is unstable. webpack/webpack#7179 (comment) To ensure that every bundled files have consistent hash names based on it's contents, use [contenthash] instead of [chunkhash].
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
I'm finding that the chunkhash varies between builds in v4. Using the diff utility between the the different files shows no differences. Attempting to narrow the codebase down reduces the frequency of different hashes.
If the current behavior is a bug, please provide the steps to reproduce.
I've been unsuccessful in creating a small test case as it's just too inconsistent and would take such an enormous amount of time for me to figure out by slicing and dicing our codebase.
I'm happy to help as much as I can to find a repro, but I'd need some information about diagnostics I can turn on to figure out what's happening.
What is the expected behavior?
The chunkhash should be consistent, as does in version 3.
If this is a feature request, what is motivation or use case for changing the behavior?
Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
Webpack 4.6.0, Node 8.9.4, OS X 10.13.4
Here's our webpack.config.js
The text was updated successfully, but these errors were encountered: