[英]npm update is not updating the version in package.json file
I am trying to update specific package in my project.我正在尝试更新项目中的特定 package。 I have checked it using
npm outdated
and then I run this command to update this package: npm update nameofpackage
ie, npm update slugify
.我已经使用
npm outdated
检查了它,然后运行此命令来更新此 package: npm update nameofpackage
即npm update slugify
。
My package.json file is not got updated after that, although when i run npm outdated again it shows no outdated package. It means it got updated but my package.json file still shows the older version of the package.我的 package.json 文件在那之后没有得到更新,尽管当我再次运行 npm 过时时它显示没有过时的 package。这意味着它已经更新但是我的 package.json 文件 still3218 的 still3218 显示旧版本
Please let me know how can I update my package.json file also.请让我知道如何更新我的 package.json 文件。 I have tried
npm update slugify --save
also but it didn't worked for me.我也尝试过
npm update slugify --save
但它对我不起作用。
The objective of the npm update
command is to update your package-lock.json
according to what you have specified in the package.json
file. npm update
命令的目的是根据您在package.json
文件中指定的内容更新您的package-lock.json
。 This is the normal behavior.这是正常行为。
If you want to update your package.json file, you can use npm-check-updates : npm install -g npm-check-updates
.如果你想更新你的 package.json 文件,你可以使用npm-check-updates :
npm install -g npm-check-updates
。
You can then use these commands:然后,您可以使用以下命令:
ncu
Checks for updates from the package.json file ncu
检查 package.json 文件中的更新ncu -u
Update the package.json file ncu -u
更新 package.json 文件npm update --save
Update your package-lock.json file from the package.json file npm update --save
从 package.json 文件更新你的 package-lock.json 文件 install ncu
package globally:全局安装
ncu
:
npm install -g npm-check-updates
Then these two following code:然后是下面这两个代码:
If you want to update all dependencies regardless of the minor or major update limit (~, ^ ) in the package.json file run the following code to check first for the available update options:如果要更新所有依赖项,而不管 package.json 文件中的次要或主要更新限制(~,^),请运行以下代码以首先检查可用的更新选项:
$ ncu
[====================] 4/4 100%
react 16.8.6 → 18.2.0
react-dom 16.8.6 → 18.2.0
react-scripts 3.2.0 → 5.0.1
typescript 3.3.3 → 4.9.4
Run ncu -u to upgrade package.json.运行ncu -u升级package.json。
Note : the npm update
only checks for updates respecting semver (see the documentation here .注意:
npm update
仅检查关于 semver 的更新(请参阅此处的文档。
ncu -u
Then run npm update
command to update package-lock.json and optimize dependency update in package.json.然后运行
npm update
命令更新package-lock.json并优化package.json中的依赖更新。
npm update --save
Finally, run the following command to install packages:最后,运行以下命令来安装包:
npm install
Note : ncu only update the package.json file.注意:ncu 仅更新 package.json 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.