简体   繁体   English

npm更新不是更新package.json文件中的版本

[英]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 nameofpackagenpm 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-updatesnpm install -g npm-check-updates

You can then use these commands:然后,您可以使用以下命令:

  1. ncu Checks for updates from the package.json file ncu检查 package.json 文件中的更新
  2. ncu -u Update the package.json file ncu -u更新 package.json 文件
  3. npm update --save Update your package-lock.json file from the package.json file npm update --save从 package.json 文件更新你的 package-lock.json 文件

Simple and Recent:简单和最近:

install ncu package globally:全局安装ncu

npm install -g npm-check-updates

Then these two following code:然后是下面这两个代码:

Check for the latest update:检查最新更新:

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

Update package.json file:更新 package.json 文件:

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.

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