angular-cli: ng build --prod is not creating unique hashes
Versions
`Angular CLI: 6.0.0 Node: 8.10.0 OS: win32 x64 Angular: 6.0.0 … animations, cli, common, compiler, compiler-cli, core, forms … http, language-service, platform-browser … platform-browser-dynamic, router
Package Version
@angular-devkit/architect 0.6.0 @angular-devkit/build-angular 0.6.0 @angular-devkit/build-optimizer 0.6.0 @angular-devkit/core 0.6.0 @angular-devkit/schematics 0.6.0 @ngtools/webpack 6.0.0 @schematics/angular 0.6.0 @schematics/update 0.6.0 rxjs 6.1.0 typescript 2.7.2 webpack 4.6.0`
Repro steps
- Create a site with ng new
- Add a lazy path with loadChildren
- ng build --prod
Observed behavior
Every time production build happens the hashes in the chunks do not change.
Desired behavior
Every single --prod build should result in unique hashes for cache busting.
Mention any other details that might be useful (optional)
Not sure if this is an issue with Angular cli or with webpack but it’s definitely effecting Angular. I believe it’s also in 5.2.10.
Not sure if this is windows only, but it happens locally on Windows and in VSTS hosted build.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 19
- Comments: 62 (20 by maintainers)
I think you’re having some weird errors and can’t debug it, and so, understandably, you’re frustrated. But this is a tracker for bugs and feature requests. If we can we also try to help with support requests. We’re very lucky to have awesome community members that also spend time trying to help people here in the issue tracker.
But we can’t really help much at all if you don’t fill in the issue template. I read your issue and have no idea what’s going wrong and how to help you. And when other users search the issue tracker and see your issue, it also doesn’t help them.
So I think the best thing to do is to close this issue, and ask you to open a new one. In that new one please fill in the issue template and give us an idea of what’s happening and how to reproduce it. That way we’ll have a chance to help you.
Closing as it looks like the issue has been solved with the answers above.
This is still an issue with 6.0.1
I’m not sure what’s happening on your VSTS build server and personally don’t have one to investigate myself. Without being able to reproduce myself there just isn’t much I can do.
On your local machine though, you say it changes so it does sound like it’s related to the build server environment. If you can get me a reproduction that I can run on my machine and see this I am happy to investigate, but without one there isn’t much hope of fixing the problem.
I can say that we don’t do anything special with hashes though. If you can’t provide me with a reproduction that doesn’t need a specific server, maybe you can try to setup a simple reproduction with just webpack and see if the problem manifests on your server as well, then submit an issue on the webpack repo.
In the 6 months since I reopened this issue there still doesn’t seem to be a reproduction that shows there’s a problem with how Angular CLI produces unique hashes for bundles.
There’s been a some very informative comments on this issue that point towards how servers and browsers interpret cache requests, like https://github.com/angular/angular-cli/issues/10641#issuecomment-491588141, https://github.com/angular/angular-cli/issues/10641#issuecomment-492714699, and https://github.com/angular/angular-cli/issues/10641#issuecomment-517290830. If you’re still seeing cache related problems, I suggest you read through these comments to see if your setup is similar.
I will again close this issue as it’s not actionable on Angular CLI. If you see it happening on your specific environment, help us by providing exact steps that we can follow on our machines to see the problem. If it happens on your CI but not on your local machine, you might have to figure out what’s different between the two.
I have facing the same issue since the hash do not change the browser does not load the changes in the page as it continues using cached version. Angular CLI: 1.7.4 Node: 8.11.3 Angular: 5.2.7
@rajaramtt try setting meta tags to your HTML, set Max age to 0, no cache. Say if the above approach didn’t work, Try setting the cache control headers to ‘no cache’ headers in your Apache or IIS server 2. If you are using https configured url, it sets max-age to 0 by default
I’m also seeing the same issue - the hashes are there but the same every time.
VSTS clears EVERYTHING between every build because the build server is a shared resource.
So you should be able to test this by simply whipping everything including all caches for angular/webpack every single time you do a build. It appears that it restarts whatever randomizer is being used and it starts at the first number again resulting in identical hashes.
i think in some scenario header no cache may not help. something like
in this case you may set your web server to redirect not found js to some js like
reload.js
that force page when it reference file that not exists anymore. like: https://gist.github.com/mix5003/0aff8719804494530790276406499e8c (this un-tested config. use on your own risk) or just create you own error handler and add this to check errors.but i still don’t know if user open module1 and i want to push hotfix to module1, how to do it. for now i put build date to
environments.ts
and force angular send it every request and check it at server side to tell client to force reload in serious case. is this way ok? or someone has a better way?@filipesilva any updates or idea on this issue, this still exists with angular 7x
@alan-agius4 it was not solved. I am having the same issue with
Angular CLI: 6.1.3
Greeting, I face the same issue. I need to re-product the project to see the changes in cloud. Does anyone solve this issue?
Just reporting back. I haven’t been able to recreate this locally, but it’s happened a few times in the past. I created a project and test script to rerun builds.
The test script waits for the user to make a code change, then given the go-ahead, recompiles with AOT and diffs all the JS/CSS files with the previous run. If the file name is somehow the same, but the contents are different, it blows up.
I haven’t been able to recreate locally with various trials, such as 2 lazy loaded modules depending on a 3rd local dependency, changing only styles, changing only html, etc.
So, instead for our CI build, I wrote a different script that does a similar test. It retrieves the last stable version of the build and does the filename match diff check. If the filenames are the same, but the contents are different, it will blow up. This should at least give me insight into when this occurs or what kind of commit causes it.
If anyone wants a template for that script, it looks like this:
I can reopen, but I will reiterate: if we don’t have a reproduction that we can follow, we cannot investigate the issue. I haven’t yet seen a report that provides anything that I can follow and get the same result as described in this issue.
So please, if you would like this to get fixed, and see it happening on your specific environment, help us by providing exact steps that we can follow on our machines to see the problem. If it happens on your CI but not on your local machine, you might have to figure out what’s different between the two.
ng build --prod
generates files without hashes AND with sourcemaps and I have this in angular.json:in package-lock.json I see that webpack version is
4.19.1
(not sure if it matters)EDIT: I feel like such a newbie 😃 I was running
npm run build --prod
thinking I am runningng build --prod
. I’m not going to delete the comment, maybe someone else does the same and finds this. Of course, actually runningng build --prod
works fine (ornpm run build -- --prod
, either way)Ok that is odd, we test for that in https://github.com/angular/devkit/blob/master/packages/angular_devkit/build_angular/test/browser/output-hashing_spec_large.ts.
I did a simple test right now by adding
console.log('hello')
tomain.ts
and I do see the hash changing:You example mentions adding a lazy route though. Can you be more specific? I don’t know how you’re adding it, and small differences in how you do it can have different behaviours.
Can you make a simple repro where you see this happening and upload it to github? Ideally I would be able to clone it, checkout a commit,
ng build --prod
, then checkout the another commit with changes,ng build --prod
and see no hash change.Still exists, Please provide an alternative solution.
@rajaramtt the most recent updates are in the comments directly above yours.
I got the same issue,
ng build --prod
generates the same hashed file names even if the code is different. In the log, I see the hash is different but the name of the files is the same.Maybe something wrong with webpack.
@trichetriche Please ensure that the project’s production configuration is configured appropriately. A new project will contain the following:
Ok, well it definitely isn’t working right because I can make changes and it still isn’t updating the hashes. We’re getting constant complaints from people about bugs we’ve already fixed and telling them to clear their cache is fixing it. I have yet to see even one file change it’s hash build to build event with changes.