Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to update all package version number in package.json when use `npm update`?

when i use npm update , i can update all package , but package version number in package.json not change , in the package.json , have devDependencies and dependencies , like this :

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "jquery": "^1.11.2"
  },
  "devDependencies": {
    "lodash": "^2.4.1"
  }
}

how to use one line command update all package and all package numbner in devDependencies and dependencies will update too.

like image 766
Mark Zhang Avatar asked Jan 19 '17 11:01

Mark Zhang


People also ask

How do I update each dependency in package json to the latest version?

Simply change every dependency's version to * , then run npm update --save .

How do I update all packages to latest version?

To update packages to the latest version, you need to use the npm install <package>@latest command. Keep in mind as these packages introduce a new major version, most likely there are breaking changes from the previous version.


2 Answers

One easy step:

$ npm i -g npm-check-updates && ncu -a && npm i

That is all. All of the package versions in package.json will be the latest.

like image 147
Matt Avatar answered Nov 15 '22 04:11

Matt


From npm documentation:

When you want to update a package and save the new version as the minimum required dependency in package.json, you can use:

npm update -S

or

npm update --save

Also As with all commands that install packages, the --dev flag will cause devDependencies to be processed as well. so your desired command is:

npm update --dev --save

Note that npm will only write an updated version to package.json if it installs a new package.

like image 39
dNitro Avatar answered Nov 15 '22 05:11

dNitro