# Destroy npm cache (./node\_modules/) based on a hash of package.json (or, if present: npm-shrinkwrap.json)?

**URL:** <https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985>\
**Category:** Build Environment\
**Tags:** nodejs, cache, npm\
**Created:** [March 28, 2016, 6:13pm UTC](https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985 "2016-03-28T18:13:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukebayes](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/lukebayes/32/2248_2.png) [@lukebayes](https://discuss.circleci.com/u/lukebayes)\
**Post date:** [March 28, 2016, 6:13pm UTC](https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985/1 "2016-03-28T18:13:36Z")

</div>

We’ve been trying to understand how Circle cache busting works in the context of node\_modules.

Whenever we introduce a new dependency to our package.json (& npm-shrinkwrap.json), our build breaks for that branch and we must click “Rebuild without cache” on the branch build UI. We frequently have to do this again when this branch is merged into master.

This was much worse (completely unusable) when we were using bcrypt and other native C++ modules that required node-gyp to build.

I suspect we’re doing something wrong here, but am not sure what it is. Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![joeellis](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/joeellis/32/2846_2.png) [@joeellis](https://discuss.circleci.com/u/joeellis)\
**Post date:** [May 9, 2016, 9:25pm UTC](https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985/2 "2016-05-09T21:25:20Z")

</div>

I actually have the exact same question as well - I’d expect a change to `package.json` or `npm-shrinkwrap.json` to bust the `node_modules` cache and run a re-install. Happy to hear any advice, hope this comment helps bump up this post to the top again for an answer.

---

<div class="post-metadata">

**Author:** ![mastilver](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mastilver](https://discuss.circleci.com/u/mastilver)\
**Post date:** [May 10, 2016, 7:30pm UTC](https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985/3 "2016-05-10T19:30:19Z")

</div>

I would try:

```auto
dependencies:
  pre:
    - npm install -g npm
  override:
    - npm update

```

The `pre` install the latest `npm`  
The `override` make sure you have the latest deps

Note: Make sure to run the **first** build without the cache

---

<div class="post-metadata">

**Author:** ![brandondoran](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/brandondoran/32/13250_2.png) [@brandondoran](https://discuss.circleci.com/u/brandondoran)\
**Post date:** [June 13, 2016, 8:26pm UTC](https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985/4 "2016-06-13T20:26:52Z")

</div>

I’m having a similar problem. When a package is removed via npm uninstall and a new shrinkwrap is generated, CircleCI seems to use the cached node\_modules. It seems like it should notice the package.json or shrinkwrap has changed and re-run npm install. I only discovered this because I was testing that if there was a required package missing then the build would fail.

I don’t understand the suggestion to run npm update. That’s just going to install the latest versions. That is not at all what we want to happen.

---

<div class="post-metadata">

**Author:** ![mediafreakch](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mediafreakch/32/13532_2.png) [@mediafreakch](https://discuss.circleci.com/u/mediafreakch)\
**Post date:** [September 2, 2016, 10:51am UTC](https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985/5 "2016-09-02T10:51:48Z")

</div>

To me `npm install` should at least check if there is a newer version available of an already cached version. The current implementation does not do that and this is wrong!

---

<div class="post-metadata">

**Author:** ![RyanMcDonald](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/ryanmcdonald/32/14435_2.png) [@RyanMcDonald](https://discuss.circleci.com/u/RyanMcDonald)\
**Post date:** [October 19, 2016, 7:50pm UTC](https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985/6 "2016-10-19T19:50:44Z")

</div>

Is this still not supported? Would love this feature.

---

<div class="post-metadata">

**Author:** ![jordanh](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jordanh/32/14599_2.png) [@jordanh](https://discuss.circleci.com/u/jordanh)\
**Post date:** [November 13, 2016, 12:12am UTC](https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985/7 "2016-11-13T00:12:59Z")

</div>

We’re having exactly the same issue. It means every time we branch, we’ve got to remember to rebuilt without the cache.

Here’s our original forum posting: [Npm bcrypt binary not saved to cache?](https://discuss.circleci.com/t/npm-bcrypt-binary-not-saved-to-cache/7773)

Is there any work around at all for this?

---

<div class="post-metadata">

**Author:** ![ashley](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ashley](https://discuss.circleci.com/u/ashley)\
**Post date:** [January 5, 2017, 10:55pm UTC](https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985/8 "2017-01-05T22:55:27Z")

</div>

Getting similar error. We use greenkeeper to keep up to date NPM packages and seem to be running into a cache issue after the npm install -g command runs

tried the update suggestion but that didn’t work

```auto
npm ERR! Linux 3.13.0-106-generic
npm ERR! argv "/home/ubuntu/nvm/versions/node/v6.1.0/bin/node" "/home/ubuntu/nvm/versions/node/v6.1.0/bin/npm" "update"
npm ERR! node v6.1.0
npm ERR! npm v3.3.12
npm ERR! path /home/ubuntu/-api-data/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/node_modules/websocket-extensions
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename

npm ERR! enoent ENOENT: no such file or directory, rename '/home/ubuntu/-api-data/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/node_modules/websocket-extensions' -> '/home/ubuntu/-api-data/node_modules/firebase/node_modules/websocket-extensions'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR! /home/ubuntu/-api-data/npm-debug.log

npm update returned exit code 254

Action failed: npm update

```

---

<div class="post-metadata">

**Author:** ![felixfbecker](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felixfbecker/32/16299_2.png) [@felixfbecker](https://discuss.circleci.com/u/felixfbecker)\
**Post date:** [June 13, 2017, 1:46pm UTC](https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985/9 "2017-06-13T13:46:28Z")

</div>

Circle should not cache node\_modules, it should cache the npm cache. Is there any way to disable caching node\_modules? I have to rebuild without cache almost every time with npm 5’s package-lock.json.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:38am UTC](https://discuss.circleci.com/t/destroy-npm-cache-node-modules-based-on-a-hash-of-package-json-or-if-present-npm-shrinkwrap-json/2985/10 "2018-06-18T11:38:08Z")

</div>


