使用“ npm ci”代替“ npm install”进行确定性的项目设置

jba*_*ndi 5 javascript npm npm-ci

Given a project where the package-lock.json is managed in source control with the goal that all developers on the team get exactly the same dependencies.

From the documentation of npm I think developers should use npm ci to set up their development environment and probably also later when dependencies are updated.

However the instructions I see in typical npm projects is still to use npm install.

Is there a reason developers should use npm install instead of npm ci? Does npm ci have disadvantages in this scenario?

I understand that npm ci does delete the whole node_modules and therefore potentially re-download some dependencies that were already present.

But with npm install I had regularly the case that an npm install is actually changing the package-lock.json (see links below), which is definitely not what is expected in a traditional project setup, where the main goal is that all developers get the same environment.
Therefore I would like to recommend to use npm ci.

Examples of "unexpected" behavior of npm install:

And*_*ndy 0

没有理由在本地构建存储库或更新依赖项时使用而不是因为它使用 npm 缓存,速度与 大致相同),但有以下情况可能是首选:npm cinpm inpm inpm i

  1. 您实际上希望自动接收直接依赖项的次要/补丁更新;
  2. 如果您对 中的版本进行了手动更改package.json并希望它们胜过package-lock.json.

  • 如果您是独立开发人员,那可能没问题。如果没有,`npm ci` 可以防止很多“它在我的计算机上运行”的奇怪问题。另一方面,“npm ci”无法更新单个依赖项;这就是`npm install`的功能。 (2认同)