问题
What is the difference between the command npm update and the package npm-check-updates? Is it fully safe to use the latter?
It seems after executing npm update
not all packages are updated, thus it seem it is incomplete. Many other popular SO answers refer to use first the prior command and then the latter, but I still do not understand what the latter does that the prior does not.
回答1:
npm-check-updates
will only modify your package.json
file. Once you've run that command, you'll then need to run a separate npm install
to grab those changes. On the other hand, npm update
will do all of that, and not give you the chance to check what is being updated beforehand.
There used to be an annoyance that npm update
did not update the package.json
file but this is no longer the case from 5.0.0. And way back when, it also looked at package dependencies which caused no end of problems for a lot of people.
The key difference between the two is that you can run ncu
(the alias for npm-check-updates
) and, by default, it will not update your packages - merely tell you what packages need to be updated.
For example, below is the output from one of my legacy projects. Here, you can see that a few grunt
packages are out of date, mainly because I no longer work on this project, prefer write build scripts in npm, and haven't had the time to update older projects.
λ ncu
Checking D:\Github\XQSF_Master\web\package.json
[====================] 10/10 100%
grunt ^1.0.3 → ^1.0.4
grunt-contrib-clean ^1.0.0 → ^2.0.0
grunt-contrib-cssmin ^2.2.1 → ^3.0.0
grunt-contrib-uglify ^3.2.1 → ^4.0.1
grunt-sass ~2.0.0 → ~3.0.2
Run ncu -u to upgrade package.json
No changes to my project were made - it simply told me what needed to be updated. This is why I prefer npm-check-updates
. By default it doesn't make any changes.
If you DO want changes to be made by ncu, simply run ncu -u
. This will update your package.json
, but you will still need to run npm install
for the node_modules
folder to be updated to your new packages.
来源:https://stackoverflow.com/questions/57069622/command-npm-update-vs-package-npm-check-updates