2

In my package.json file i want to update dependencies & devdependencies in my project.

I don't know how to update it

1
  • 1
    npm update simple as that Commented Sep 17, 2020 at 6:12

2 Answers 2

6

I will post 2 approaches

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

    npm update --save-dev 
  2. To update to a new major version all the packages, install the npm-check-updates package globally:

    npm install -g npm-check-updates 

    then run it:

    ncu -u 

    This will upgrade all the version hints in the package.json file, to dependencies and devDependencies, so npm can install the new major version.

    You are now ready to run the update:

    npm update 

    note npm update will ignore devDependencies unless the -- dev flag is added.npm update will not upgrade to the latest major version. It makes sense since major releases frequently introduce breaking changes, and it needs to be handled with caution.

Sign up to request clarification or add additional context in comments.

3 Comments

In your note, you mention the -- dev flag; I think you meant the --save-dev flag?
Does not work in my case. Both devDependencies won't update with --save-dev. Is there any other reason npmwould skip these?
Just use --save flag, it does the job
1

You can update all dependencies and devDependencies to their respective new major versions by running the following commands:

npm install -g npm-check-updates ncu -u rm -rf node_modules && rm package-lock.json npm i --legacy-peer-deps 

Please note that npm i --legacy-peer-deps is recommended because there might be some errors (due to issues with resolving the dependency tree) while you install new package versions using the approach above. If you run into any further error with any particular package, just manually choose the right version for that specific error-causing package.

1 Comment

What the heck is ncu -u??

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.