禁用 npm 缓存 [英] Disable npm cache
问题描述
前段时间我在构建机器上的 npm 缓存方面遇到了问题.有时我们不得不手动执行npm cache clean
,这解决了我们仍然不确定是什么原因导致的各种问题.所以一段时间后,我们在所有构建脚本中都包含了 npm cache clean
,从那时起我们就没有使用 npm i
的神秘问题,但是现在并行构建显然会相互影响.
Some time ago I had trouble with the npm cache on our build machines. From time to time we had to do npm cache clean
by hand, and that solved various issues that we are still not certain about what caused them. So after a time we included npm cache clean
in all our build scripts, since then we did not have mysterious problems with npm i
, however now parallel builds obviously affect each other.
对我来说最好的解决方案似乎是完全关闭 npm 缓存机制,但我不知道如何做到这一点.
For me the best solution seems to be completely turn off the npm caching mechanism, but I couldn't find out how to do that.
推荐答案
您可以通过为一系列 npm 命令创建一个新目录并将其 cache
设置为空来解决并行构建的问题目录,然后删除该目录.喜欢:
You could fix the problem with parallel builds by creating a new directory for one series of npm commands and set its cache
to that empty directory and then remove that directory afterwards. Like:
export npm_config_cache=$(mktemp -d)
npm ...
...
rm -rf $npm_config_cache
这将消除对 npm cache clean
的需求,因为它总是从空缓存开始.
This would remove the need for npm cache clean
as it would always start out with an empty cache.
这篇关于禁用 npm 缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!