In our Bitbucket pipeline, we are caching the node modules.
We are doing this to make sure we don't download the node modules if it is already present in the cache.
But when there is a change in the package.json dependency (added a new npm package and used in the components), we are expecting the pipeline to re-fetch the node modules instead of taking it from the cache.
What happens currently is: when there is a cache for node modules exists in pipeline irrespective of the current status of package.json, the node cache is being used. Ideally, node modules has to be refreshed in refernce to the package.json
So, the pipeline fails. When we delete the node cache manually and re-run the same pipeline, it gets succeeded.
Thanks in advance for your help.
I don't know much about node, but my understanding is that if you update a dependency in package.json (eg. add a new package that you haven't used before or update to the latest version of an existing package) then that new dependency won't be present in the cache (and so it will have to be downloaded). Are you saying that the cache is giving you the wrong version of a package (ie. with a different version number from the one you were expecting)?
Ok, I think I understand now. You're saying that the build works but it needs to download the new dependencies every time because the cache doesn't get updated? That's expected behaviour. By design the cache only gets updated automatically once per week. If you want to update it earlier then you need to manually delete it. We don't currently support automatic cache updates because it's actually a bit tricky to do reliably (many build tools will make minor updates to their caches on every build, such as by changing timestamps, even though there are no changes to dependencies, so detecting when a cache has changed generically across all tools is not trivial).
But we do have an open (and highly voted) issue for improving the cache system: https://bitbucket.org/site/master/issues/16314/refresh-caches-when-dependencies-are
I'd recommend you watch and vote on that issue.
Yes. Whenever there is a change in the "package.json" the node cache has to be updated automatically. If the node cache is not updating automatically, then we have to delete the node cache manually and run the build. Then the build will succeed.
I'm just curious to know these:
I'm still not certain I understand the problem you're seeing though. If you don't delete the cache, does the build fail? I don't understand why the build would fail. I would expect "npm install" to download the missing dependencies that aren't already in the cache.
The problem is that some node_modules binaries are only compatible with specific versions of node. Running npm i on a cache from a different node version fails outright.
When we have different node versions targeted by the bitbucket-pipelines.yml file on different branches then only the branches with the same node version as the one the cache was initialized with will succeed.
Our workaround was to go through all our PRs and ensure the node version was consistent. Delete the cache and rebuild with the new targeted version. Luckily for us this works and we don't change the node version very often.
However, I'm not sure this is a solution that will work for everyone.
It would be nice to tie the node cache type to the node version and create multiple caches for each combination. This would avoid the problems altogether.
...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events