Search code examples
node.jsnpmtravis-ciyarnpkg

Should I have Travis cache node_modules or $HOME/.npm


I'm quite confused about which directory is optimal for caching. I've seen both used and recommended, but no actual comparison as to why go one way or the other.

For instance, the Travis blog itself recommends:

cache:
  directories:
    - node_modules

However, thousands of places use this instead:

cache:
  directories:
    - $HOME/.npm

So why use one over the other, and why not include both?


Solution

  • I noticed caching the node_modules folder caused problems (build fails) while caching the .npm cache avoided it. I believe it's because the .npm cache doesn't store compiled native modules while the node_modules folder does. So when you test different versions of node, as is common in Travis-CI, it will try to load a native module compiled for say node 4 in node 6 and barf.