最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to change the version of package in package.json - Stack Overflow

programmeradmin0浏览0评论

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:

npm install [email protected]

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.

How to delete / update / change the version in package.json through terminal?

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:

npm install [email protected]

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.

How to delete / update / change the version in package.json through terminal?

Share Improve this question asked Sep 28, 2017 at 13:22 EduardEduard 9,21511 gold badges46 silver badges72 bronze badges 2
  • What version of npm are you using? Did you notice a file called package-lock.json? – msanford Commented Sep 28, 2017 at 13:29
  • Also, ncu may be useful for you: npmjs./package/npm-check-updates – msanford Commented Sep 28, 2017 at 13:31
Add a ment  | 

2 Answers 2

Reset to default 5

You need to add --save to the mand in both install and uninstall cases.

This way, when uninstalling with --save, the package's line will be erased from package.json as well as from node_modules. And when installing with --save, the package's line will be added to the package.json, as well as the node_modules.

So, you should go like that, for example:

npm uninstall react --save    
npm install [email protected] --save

Since the question asked about changing the version in package.json, I'll add a quick answer showing that. Simply change the line in package.json to specify the exact version like so:

"react": "15.0.0",

save, and then run npm install. You can check which exact version is installed by looking in package-lock.json as well.

发布评论

评论列表(0)

  1. 暂无评论