How do I update devDependencies in NPM?

node.jsNpm

node.js Problem Overview


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?

node.js Solutions


Solution 1 - node.js

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>

Solution 2 - node.js

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

Solution 3 - node.js

These steps worked for me :

  1. npm install -g npm-check-updates
  2. ncu -u
  3. npm update
  4. npm install

Solution 4 - node.js

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

Update works fine with: npm update

Solution 5 - node.js

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

Solution 6 - node.js

  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 https://stackoverflow.com/questions/66239691/what-does-npm-install-legacy-peer-deps-do-exactly-when-is-it-recommended-wh
  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 :)

Solution 7 - node.js

What worked for me is installing individual dev dependencies like this

npm install [email protected] --save --only=dev

Solution 8 - node.js

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

Solution 9 - node.js

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.

Solution 10 - node.js

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMattView Question on Stackoverflow
Solution 1 - node.jsdeckerdevView Answer on Stackoverflow
Solution 2 - node.jsMichael ThompsonView Answer on Stackoverflow
Solution 3 - node.jsAlferd NobelView Answer on Stackoverflow
Solution 4 - node.jsChris SpieglView Answer on Stackoverflow
Solution 5 - node.jsjmarceliView Answer on Stackoverflow
Solution 6 - node.jsDaniel DanieleckiView Answer on Stackoverflow
Solution 7 - node.jsVarshaView Answer on Stackoverflow
Solution 8 - node.jsGilad PelegView Answer on Stackoverflow
Solution 9 - node.jsRick DeckardView Answer on Stackoverflow
Solution 10 - node.jsAman SharmaView Answer on Stackoverflow