Upgrade Node Modules To Their Latest Versions With NPM 7
Check What's Available For Update
For Minor And Patch Version Upgrades
npx npm-check-updates --target minor --upgrade; npm install
This will update versions in your package.json and package-lock.json files for modules starting with
^ (i.e. the minor and patch versions)
For Major Versions
Do a one time install of:
npm install -g npm-check-updates
Then run these two commands:
ncu -u npm update
ncu -u command updates the package.json so that when you run
npm update it pulls the new major versions.
The official node documentation says to use
npm updatefor minor versions and that "Since npm version 5.0.0, npm update will update the package.json with the updated version. Use npm update --no-save to not update package.json."
This is not the case in version 7. See this issue for reference.
npm updatecommand does update
package-lock.json. I don't know if it matters programmatically that the
package.jsonfile isn't updated, but it throws me off. That's what lead me to search for the above solution. (Actually, I'm not sure if it updated
package-lock.json. Your milage may vary.)
The docs page is currently the third search result for me. The first two are from 2015 and 2017, respectively and list even more outdated methods.
Putting this in my grimoire but also linking to the docs in hopes that will raise it in the search results (and that it'll be corrected for v7).