简体   繁体   English

package-lock.json 从 package.Z466DEEC76ECDF324FCA6D385D8Z 删除 package 后未更新

[英]package-lock.json not updated after removing a package from package.json?

If i manually add a package to package.json and then run npm install , my package-lock.json gets updated with that new package's dependencies. If i manually add a package to package.json and then run npm install , my package-lock.json gets updated with that new package's dependencies.

However, if i then manually delete that package from package.json from npm install , that package's dependencies are not removed from package-lock.json . However, if i then manually delete that package from package.json from npm install , that package's dependencies are not removed from package-lock.json .

So - package-lock.json only gets modified when adding/updating packages in package.json ?所以 - package-lock.json只有在package.json中添加/更新包时才会被修改? Not when removing?卸的时候不行吗?

This is a known issue with npm.这是 npm 的一个已知问题。

See issue : package-lock.json file not updated after package.json file is changed请参阅问题:更改 package.json 文件后未更新 package-lock.json 文件

" For now I'm working around it by changing my npm install command to rm -f package-lock.json && npm install. Obviously, that's not an elegant solution, and somewhat defeats the purpose of having a lockfile in the first place." " 现在我正在通过将我的 npm install 命令更改为 rm -f package-lock.json && npm install 来解决这个问题。显然,这不是一个优雅的解决方案,并且在某种程度上违背了首先拥有锁定文件的目的。 ”

rm -f package-lock.json && npm install

This is supposed to be fixed in : https://github.com/npm/npm/pull/17508这应该在: https : //github.com/npm/npm/pull/17508 中修复

See article : https://medium.com/coinmonks/everything-you-wanted-to-know-about-package-lock-json-b81911aa8ab8 for a better understanding.请参阅文章: https : //medium.com/coinmonks/everything-you-wanted-to-know-about-package-lock-json-b81911aa8ab8以获得更好的理解。

From the NodeJs docs来自NodeJs 文档

The package-lock.json sets your currently installed version of each package in stone, and npm will use those exact versions when running npm install. package-lock.json 设置了你当前安装的每个包的版本,当运行 npm install 时,npm 将使用这些确切的版本。

NPM by default will read the package-lock.json file. NPM 默认会读取 package-lock.json 文件。

Therefore, in the first scenario, npm is reading the package entry from package.json since that's the only file which has an entry of the particular package.因此,在第一种情况下,npm 正在从 package.json 读取包条目,因为这是唯一包含特定包条目的文件。 Whereas in the second scenario, it is reading it from package-lock.json, as is its default behaviour而在第二种情况下,它从 package-lock.json 中读取它,这是它的默认行为

Removal of package-lock.json should be only done in case of corrupted lock file.仅在锁定文件损坏的情况下才应删除 package-lock.json。 To remove package you should just use npm cli (it will update lock file)要删除 package 您应该只使用 npm cli(它将更新锁定文件)

npm uninstall <package>

This is a good explanation.这是一个很好的解释。 https://stackoverflow.com/a/54127283/5040275 https://stackoverflow.com/a/54127283/5040275

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM