The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Upgrade Node Modules To Their Latest Versions With NPM 7

TODO: Pull subtitle into page object

### Check What's Available For Update

code_start_default_section code_end_default_section

The `ncu -u` command updates the package.json so that when you run `npm update` it pulls the new major versions.

### Notes

- The official node documentation says to use `npm update` for 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.

- The `npm update` command does update `package-lock.json`. I don't know if it matters programmatically that the `package.json` file 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).

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Upgrade Node Modules To Their Latest Versions With NPM 7

-- p

### Check What's Available For Update

-- code/
-- bash

npm outdated

-- /code

-- p

### For Minor And Patch Version Upgrades

-- code/
-- bash

npx npm-check-updates --target minor --upgrade; npm install

-- /code

-- p

This will update versions in your package.json and package-lock.json files for modules starting with `~` and `^` (i.e. the minor and patch versions)

-- p

### For Major Versions

-- p

Do a one time install of:

-- code/
-- bash

npm install -g npm-check-updates

-- /code

-- p

Then run these two commands:

-- code/

ncu -u
npm update

-- /code

-- p

The `ncu -u` command updates the package.json so that when you run `npm update` it pulls the new major versions.

-- p

### Notes

-- p

- <<link|The official node documentation|https://nodejs.dev/learn/update-all-the-nodejs-dependencies-to-their-latest-version>> says to use `npm update` for 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."

-- p

This is not the case in version 7. See <<link|this issue|https://github.com/npm/cli/issues/2704>> for reference.

-- p

- The `npm update` command does update `package-lock.json`. I don't know if it matters programmatically that the `package.json` file 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.)

-- p

- 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.

-- p

- 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).


-- categories
-- JavaScript

-- metadata
-- date: 2021-11-17 12:40:44
-- id: 213xfeh7
-- status: published
-- type: post
-- SCRUBBED_NEO: false
-- site: aws