简体   繁体   English

如何在 package.json 中更改包的版本

[英]How to change the version of package in package.json

If I uninstall a package from my project like this:如果我像这样从我的项目中卸载一个包:

npm uninstall react     

the line related to this package in package.json file does not disappear, and then when I install a different version of this package, like this: package.json 文件中与此包相关的行不会消失,然后当我安装此包的不同版本时,如下所示:

npm install react@15.0.0

the package gets installed to the node_modules, but the version in package.json remains to be unupdated, meaning that it is still the old version of a package, that I had before the uninstallation.该软件包已安装到 node_modules,但 package.json 中的版本仍未更新,这意味着它仍然是我在卸载之前拥有的旧版本软件包。

How to delete / update / change the version in package.json through terminal?如何通过终端删除/更新/更改package.json中的版本?

You need to add --save to the command in both install and uninstall cases.在安装和卸载情况下,您都需要将--save添加到命令中。

This way, when uninstalling with --save, the package's line will be erased from package.json as well as from node_modules.这样,当使用 --save卸载时,包的行将从 package.json 和 node_modules 中删除。 And when installing with --save, the package's line will be added to the package.json, as well as the node_modules.当使用 --save安装时,包的行将添加到 package.json 以及 node_modules 中。

So, you should go like that, for example:所以,你应该这样做,例如:

npm uninstall react --save    
npm install react@15.0.0 --save

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

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