目前在部署项目的时候,遇到执行npm ci的时候出现错误,但是改为npm install时,就能正常部署。所以就去网上搜索了它们之间的区别。
以下是官网 npm ci的信息:https://docs.npmjs.com/cli/v7/commands/npm-ci
此命令类似于npm install,不同之处在于它用于自动化环境,例如测试平台、持续集成和部署——或者任何您想要确保完全安装依赖项的情况。
npm ci在以下情况下会明显更快:
有一个package-lock.json或npm-shrinkwrap.json文件。
文件node_modules夹丢失或为空。
简而言之,使用npm install和之间的主要区别npm ci是:
该项目必须有一个现有的package-lock.json或 npm-shrinkwrap.json.
如果包锁中的依赖项与 中的依赖项不匹配package.json, npm ci将出错退出,而不是更新包锁。
npm ci一次只能安装整个项目:不能使用此命令添加单个依赖项。
如果 anode_modules已经存在,它将在npm ci开始安装之前自动删除。
它永远不会写入package.json或任何包锁:安装基本上被冻结。
This command is similar to npm install, except it's meant to be used in automated environments such as test platforms, continuous integration, and deployment -- or any situation where you want to make sure you're doing a clean install of your dependencies.
npm ci will be significantly faster when:
There is a package-lock.json or npm-shrinkwrap.json file.
The node_modules folder is missing or empty.
In short, the main differences between using npm install and npm ci are:
The project must have an existing package-lock.json or npm-shrinkwrap.json.
If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock.
npm ci can only install entire projects at a time: individual dependencies cannot be added with this command.
If a node_modules is already present, it will be automatically removed before npm ci begins its install.
It will never write to package.json or any of the package-locks: installs are essentially frozen.