The Be Sure Blog

Code Snippets | Problem Solving | Tips & Tricks

The Be Sure Blog banner

Keeping package.json dependencies up to date

posted on 22.3.2023 by Below Surface in "Npm"

An easy and in my experience reliable way to keep the package.json dependencies up to date, is to use npm-check-updates. Just install it with:

$ npm i -g npm-check-updates

And then run this command in your repository, where the package.json is present:

$ ncu

If any update is available, the output will be something like this:

@next/font           ^13.1.6  →   ^13.2.4
@reduxjs/toolkit      ^1.9.2  →    ^1.9.3
@types/node          18.13.0  →   18.15.5
@types/react         18.0.27  →   18.0.28
@types/react-dom     18.0.10  →   18.0.11
autoprefixer        ^10.4.13  →  ^10.4.14
eslint                8.33.0  →    8.36.0
eslint-config-next    13.1.6  →    13.2.4
next                  13.1.6  →    13.2.4
npm-check-updates    ^16.7.4  →  ^16.7.13
react-markdown        ^8.0.5  →    ^8.0.6
sass                 ^1.58.0  →   ^1.59.3
tailwindcss           ^3.2.6  →    ^3.2.7
typescript             4.9.5  →     5.0.2

To apply the suggested changes (on the right hand side), run:

$ ncu -u

This will only change package.json, so additional, you have to run:

$ npm i

To finally install the new version for each listed dependency.

Tags:

ncu
npm-check-updates
npm
node.js
package.json dependencies
upgrade

Sources:

https://www.npmjs.com/package/npm-check-updates