207

npm update seems to just update the packages in dependencies, but what about devDependencies.

Right now you can install devDependencies by running npm install ., but this doesn't work for npm update .

Any ideas?

vaultah
  • 44,105
  • 12
  • 114
  • 143
Matt
  • 22,224
  • 25
  • 80
  • 116
  • 1
    I just ran into the same thing. I'm surprised at this asymmetry between `npm install` and `npm update`. I worked around it by deleting my `node_modules` directory and then running `npm install` again, but it sure seems like there should be a better way. – Joe White Apr 14 '12 at 02:01
  • 7
    I opened a [bug report](https://github.com/isaacs/npm/issues/2369) for this behavior. We'll see what happens. – Joe White Apr 14 '12 at 12:21
  • This may be because the NPM devs thought that people would use `npm link` for doing dev environments. – Julian Knight Jul 02 '12 at 10:58
  • Does this answer your question? [How to update each dependency in package.json to the latest version?](https://stackoverflow.com/questions/16073603/how-to-update-each-dependency-in-package-json-to-the-latest-version) – Henke Feb 24 '22 at 12:34

10 Answers10

185

To update package.json in addition to the local modules, run

npm update --save-dev

Alternatively, the same command to save time

npm update -D

You can view the full detail of update, or any command for that matter through

npm help <cmd>
deckerdev
  • 2,766
  • 2
  • 21
  • 23
66

Install npm-check-updates (https://www.npmjs.org/package/npm-check-updates), then jump into your project folder and run:

npm-check-updates

And to update and save changes to your package.json file:

npm-check-updates -u
Michael Thompson
  • 4,181
  • 1
  • 29
  • 24
17

These steps worked for me :

  1. npm install -g npm-check-updates
  2. ncu -u
  3. npm update
  4. npm install
Alferd Nobel
  • 3,185
  • 2
  • 30
  • 35
  • 2
    Why we have to use third party thing for this kind of work? So weird. I could not make npm update change package.json – srknzl Mar 19 '21 at 18:02
  • 3. is probably not needed, you can skip it. – Diego Ferri Apr 29 '21 at 08:28
  • step 4. is obviated by step 3. The response from @Daniel Danielecki does a better job of explaining what each of these steps actually does. https://stackoverflow.com/a/68375286/413538 – JamesWilson Mar 10 '22 at 03:33
11
  1. npm outdated - for an overview what's outdated
  2. npm install -g npm-check-updates - as pointed correctly by Michael
  3. ncu -u - it'll automatically update all dependencies (also dependencies, i.e., it's of course different than devDependencies) versions in package.json, without reinstalling it yet. It'll just change the "numbers" in package.json
  4. npm update - actual dependencies installation
  5. (Optional, depending by scenario) you might need to use the flag --force, or (new in NPM v7) --legacy-peer-deps to complete the process. You can read about difference between those 2 on What does npm install --legacy-peer-deps do exactly? When is it recommended / What's a potential use case?
  6. (Optional) you can validate it using ncu -u and for correctly updated dependencies you should see the text All dependencies match the latest package versions :)
Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
5

This problem does no longer excise with the current version of NPM (1.3.11).

Update works fine with: npm update

Chris Spiegl
  • 345
  • 3
  • 8
  • 3
    Unfortunately, it does not. Here's the [thread tracking the issue](https://npm.community/t/npm-update-doesnt-save-package-json/872/6?u=dandv). – Dan Dascalescu Sep 26 '18 at 03:04
4

If you are using outdated npm version it might be the problem. So before any other commands execute:

sudo npm install npm -g

or (if above doesn't work):

sudo npm update npm -g

Then relaunch the console (in order for changes to take effect). Now you can check your new npm --version and if it is up to date execute:

npm update

or (if you prefer):

npm update --save-dev
jmarceli
  • 19,102
  • 6
  • 69
  • 67
  • Unfortunately, this doesn't work in npm 5. Here's the [thread tracking the issue](https://npm.community/t/npm-update-doesnt-save-package-json/872/6?u=dandv). – Dan Dascalescu Sep 26 '18 at 03:04
2

I ran into the same problem as OP had, and found no solution, so I decided to write a Grunt plugin that will auto-update my devDependencies..

It's on Github, I'd love to get some input and collaborations in order to make it the best tool that NPM hasn't provided.

Basically it will auto-update your outdated development dependencies with a simple Grunt Task.

https://github.com/pgilad/grunt-dev-update

Gilad Peleg
  • 2,010
  • 16
  • 29
2

What worked for me is installing individual dev dependencies like this

npm install react-test-renderer@15.6.1 --save --only=dev
Varsha
  • 29
  • 6
2

i found the answer onhttps://nodejs.dev/learn/update-all-the-nodejs-dependencies-to-their-latest-version and this is working for me for all the major release as well

npm install -g npm-check-updates
ncu -u
npm update

to check the outdated package use

npm outdated
Aman Sharma
  • 311
  • 1
  • 8
  • 22
1

One (slow) way to do force the update, is to remove the node_modules directory, and then do npm install again.

This was a known bug of the npm update command, which has been fixed on the development branch of npm, see here: https://github.com/isaacs/npm/pull/3863

It should land on the latest stable version of npm pretty soon.

Rick Deckard
  • 1,239
  • 1
  • 11
  • 10
  • 1
    In case of npm > v5 you would also need to remove `package-lock.json` to make this work, otherwise it will just install the versions listed in that lock file. – karfau Oct 10 '17 at 08:23
  • Also, this won't update `package.json` for you. Here's the [thread tracking the issue](https://npm.community/t/npm-update-doesnt-save-package-json/872/6?u=dandv). – Dan Dascalescu Sep 26 '18 at 03:05