-
Notifications
You must be signed in to change notification settings - Fork 12k
ng build --prod is not creating unique hashes #10641
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
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. |
What part of the issue template isn't filled in? The repro steps? ng new project name Observe that the hashes are IDENTICAL. They shouldn't be. Every time prod code is built every chunk should have unique hashes in the file name for cache busting per the documentation. Didn't think I need to state the obvious with an issue of angular-cli or webpack not creating new hashes on production build, it's self-explanatory. |
And for the record I did fill in the entire template, but the output of ng --version that it instructs to copy and paste borks GitHub markdown. I've cleaned it up. |
Thank you for cleaning up the output and clarifying the information. We change the hashes per bundle content, not per build. So between two builds, if the content of the bundle did not change, the hash will not change. |
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. |
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
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, |
Here's our base routemodule:
Each module also has sub routes that are lazy loaded. These generate chunks. No matter what chunk you change I get the same hash. While I have seen it sometimes on my local computer, build to build change this way, on VSTS hosted build servers which blow away everything you just did every session and thus don't have cache, I get exactly the same hashes always (15 builds today, no difference to 31 chunks even though 6 chunks have changed from check-ins today) |
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. |
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 am using Angular 5.2 with angular/cli 1.7.4 and also facing the same issue, for example I have lazy loaded module where I am providing service and using some value from service in html, even after I am updating that services ts file prod build does not change the chunks hash, and as a result we are having caching issues |
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. |
I am facing the same issue. I was using Angular 5.2 and everythin was working fine. I decided to migrate to Angular 6, and since then, there is no more hashing.
I don't know if this is about lazy loading, but my modules are lazy loaded too. |
@trichetriche Please ensure that the project's production configuration is configured appropriately. A new project will contain the following:
|
What a dumbf... I am, thank you for that information @clydin ! (I'll keep my comment up there, I probably won't be the only one looking for that) |
yep ok so after adding all properties to
it works fine |
@intergleam In CLI 6+ the |
Closing as it looks like the issue has been solved with the answers above. |
@alan-agius4 it was not solved. I am having the same issue with |
Same issue for me. Here my specs Angular CLI: 6.2.3 Package Version @angular-devkit/architect 0.8.3 |
I'm also seeing the same issue - the hashes are there but the same every time. |
The hashes should only change if you made changes to the code that resulted in the output differing. (e.g., adding several extra spaces to the end of a source file should not change the output). |
Hashes don't change in my project either even after doing major modifications in the codebase. I have to Ctrl+F5 every time I make changes to reload them. |
@clydin which makes sense as to why it always works in CI but it's not working locally. Is there a way to force it? |
I was stuck in the same boat as a few others. Build config looked good with regards to output hashing, but major changes to the codebase still wouldn't change the hashes that were generated. I upgraded typescript from 2.7.2 to 2.9.2 for an unrelated issue, and this started working?!? Wanted to share the experience and see if it helps others. |
@mtraynham thank you for taking the time to trace this and help debug it. I understand it's not easy, and the setup you're using must have taken a fair bit of time to put together, but I really appreciate it because at the moment it's the best chance we have at getting to the bottom of it. |
@filipesilva Any updates on this? |
@filipesilva is there a way to force a new hash for every single file even if it hasn't been changed? I know for some people they wouldn't want this, but it actually would help us out on our new releases. |
@filipesilva Any updates? Having a ton of issues with this. I would be okay with a force of changing hash on all files too. |
@joe704la like I said before, I cannot reproduce it and without a reproduction I cannot fix it. I'm waiting for @mtraynham's results. Maybe you can try and reproduce it in a similar way? |
@filipesilva do you have an answer to the other question about forcing a unique hash for all files after each build and not just changed files? |
That's not how these hashes work really. We use Webpacks file hashing functionality, and it determines the hash from the file content. If the file content is the same, Webpack makes the same hash. So it's not that we determine what files changed and give them a new hash, but rather that the file content is different and thus gets a new hash. |
@filipesilva okay, that makes sense. Thank you |
I just want to chime in real quick. I remembered from a while ago, when I was using straight Webpack without Angular CLI, I ran into this particular bug. It suggests hashes are based off the original source and not necessarily the generated output. Based on that bug's documentation, the chunkhash might not change if:
I didn't have this as a test case when doing local testing for this particular bug (the AngularCLI one). There may be a case where a user upgrades Angular CLI (and likely Angular), it generates different output from before, but leaves the file hashes the same. I imagine if you had no package-lock file and a very relaxed version of AngularCLI, you may easily encounter that without noticing. Or simply updating your dependencies to latest might cause it. Or if AngularCLI (and subsequent tools) somehow are non-deterministic and generate different content on every build, the source would be unchanged, but the output is different, running into this particular bug. |
@mtraynham I am not aware of the build process being non-deterministic for the same set of sources + build dependencies. The only thing that comes to mind is optimizations and tree-shaking... where the end result of a given chunk differs from the sources. But the indirection with the webpack module loader used in chunks make cross-chunk optimizations almost impossible for third party tools like Uglify/Terser. So I can't see how changes in one source file could affect another through the action of Uglify/Terser. Webpack itself also does https://github.com/webpack/webpack/tree/master/examples/side-effects though. But that wholly removes files, and can't partially change content. |
I'm seeing the issue also with Typescript 2.9.2, Angular 6.1.4
|
@paulsperanza do you have a reproduction we can follow? If you do, can you please document it here and verify the same happens on your local machine? This is a problem for which we haven't yet seen a reliable reproduction. |
I not quite sure. but i saw some comment can solve by ctrl + f5, in that case i think it not angular relate, but it a web server relate. some web server (or maybe browser) add a cache headers to
in this case i think you may add if you use nginx this is my sample config. i cache every static files. but if file not exists i force browser to not cache and re-validate everytime. |
Just faced this behaviour on a SPA, hosted on an Azure Blob storage with Azure Front Door (with dynamic caching activated). I was able to solve it (within my CD pipeline on Azure DevOps):
|
@filipesilva any updates or idea on this issue, this still exists with angular 7x |
@aburht I'm still waiting for a reproduction. No one has been able to provide me with a reproduction so far. |
@filipesilva did some ground work on this, and I assume this is due to index.html getting cached and where in index.html's script tag is referring to old build's chunks, as we know output hashing doesn't provide hashing for index.html, Any thoughts that you could think of it? |
@aburht what you describe sounds a lot like what @mix5003 and @ddhille describe. And I think it makes sense. But that's not something that should be addressed on Angular CLI, but rather on your hosting caching strategy. We probably should add something to https://angular.io/guide/deployment about caching for At the end of the day whenever caching is used, you have to decide when to invalidate the cache. That's the hard part of caching really. And there are several types of cache at play. Your server, reverse-proxy, browser, service-worker. All of these can have caches. So your deployment strategy needs to consider what caches you have up. |
@filipesilva exactly I agree, I resolved this issue setting meta tag no cache revalidate, which resolved my issue. Like you said it's a great idea to document it in deployment guide, since we now |
Any updates on this issue, Still exists with angular 7.x!. |
@rajaramtt the most recent updates are in the comments directly above yours. |
@rajaramtt try setting meta tags to your HTML, set Max age to 0, no cache. |
i think in some scenario header no cache may not help.
in this case you may set your web server to redirect not found js to some js like if (err.message) {
if (err.message.indexOf('Error: Loading chunk') !== -1) {
// TODO: be more user friendly
location.reload(true);
return;
}
} but i still don't know if user open module1 and i want to push hotfix to module1, how to do it. |
Greeting, I face the same issue. I need to re-product the project to see the changes in cloud. Does anyone solve this issue? |
Still exists, Please provide an alternative solution. |
We've been plagued by a very-hard-to-debug issue for quite a few weeks now that we have since resolved, but I feel it is very closely related to this issue. We have roughly 90 bundles optimized for different use cases throughout our application, we release every few days as new features clear for production. We upload every bundle that gets created to the same bucket (which means old files would be overwritten if they have the same file name), and we have a cache policy that always requires Since it is a I still do not have a good understanding as to why this was the case, because cURLing the files and manually generating the integrity hashes matched what was contained in the It became our assumption that some mechanism was failing the integrity check based on files changing (aka timestamps/metadata) without the filenames changing/being reloaded from cache. This is where I wish I had a better understanding of the root cause, but it seemed fishy that it was only the bundles that didn't change filename hashes between deployments that were causing the issue. In order to work around this I added a build phase after angular-cli generates the files in I do think this is a Chrome issue and not an angular-cli issue, but I do think that if the hash added to file names was the build hash instead of the content hash it would resolve this issue (for us at least). |
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 #10641 (comment), #10641 (comment), and #10641 (comment). 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. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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
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.
The text was updated successfully, but these errors were encountered: