'How to update version of a package in package-lock.json and/or package.json using npm to latest version?

Say you get a warning in some libraries in a repo about security concerns from github. You want to quickly bump the version just to make the github warnings going away. You are not worried about re-installing, rebuilding and testing.

Is there a way to do this with npm?

npm update mypackage does not do anything.



Solution 1:[1]

npm update will only update minor versions.

Eg: It will update version 1.2.3 to 1.5.2
But it will not update version 1.2.3 to 2.0.1 because there can be breaking changes.

To check new major releases of the packages, you run npm outdated

To update to a new major versions for all the packages, you can use npm-check-updates

npm install -g npm-check-updates
Then run ncu -u

This will upgrade all the versions in the package.json file, to dependencies and devDependencies, so npm can install the new major version. Now you can update packages to new major releases by npm update

Reference

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Harikrishnan