我应该有 Travis 缓存 node_modules 还是 $HOME/.npm [英] Should I have Travis cache node_modules or $HOME/.npm

查看:37
本文介绍了我应该有 Travis 缓存 node_modules 还是 $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

然而,成千上万的地方改用这个:

cache:
  directories:
    - $HOME/.npm

那么为什么要使用一个而不是另一个,为什么不包括两者?

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

推荐答案

我注意到缓存 node_modules 文件夹会导致问题(构建失败),同时避免缓存 .npm 缓存它.我相信这是因为 .npm 缓存不存储编译的本地模块,而 node_modules 文件夹存储.因此,当您测试不同版本的 node 时,正如 Travis-CI 中常见的那样,它会尝试加载为 node 4 编译的本机模块 node 6 和 barf.

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.

这篇关于我应该有 Travis 缓存 node_modules 还是 $HOME/.npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆