npm-check-updates upgrades our package.json dependencies to the latest versions, ignoring specified versions.

  • It maintains existing semantic versioning policies, i.e. "express": "^4.0.0" to "express": "^5.0.0".
  • It only modifies package.json file. We then need to Run npm install to update our installed packages and package-lock.json.
  1. Red = major upgrade
  2. Cyan = minor upgrade
  3. Green = patch upgrade

Installation

#Install globally
npm install -g npm-check-updates

Usage

  • Check the latest versions of all project dependencies:
  • Upgrade a project’s package file:

ps: First, make sure your package file is in version control and all changes have been committed. This will overwrite your package file.

  • Check global packages:
ncu -g

npm vs. ncu

Interactive Mode

Choose which packages to update in interactive mode:

ncu --interactive
//Or
ncu -i

Combine with --format group for a truly luxe experience:

Filter packages

Filter packages using the --filter option or adding additional cli arguments. We can exclude specific packages with the --reject option or prefixing a filter with !. Supports strings, wildcards, globs, comma-or-space-delimited lists, and regular expressions:

# upgrade only mocha
ncu mocha
ncu -f mocha
ncu --filter mocha

# upgrade packages that start with "react-"
ncu react-*
ncu "/^react-.*$/"

# upgrade everything except nodemon
ncu \!nodemon
ncu -x nodemon
ncu --reject nodemon

# upgrade only chalk, mocha, and react
ncu chalk mocha react
ncu chalk, mocha, react
ncu -f "chalk mocha react"

# upgrade packages that do not start with "react-".
ncu \!react-*
ncu '/^(?!react-).*$/' # mac/linux
ncu "/^(?!react-).*$/" # windows

PS: npm-check-updates has a flag -x, --reject to ignore certain packages when checking for updates. (dependencies that shouldn’t be updated)

ncu -u -x mobx,query-string  
//Will update all outdated dependencies except mobx and query-string 

we can also use a config File .ncurc.json file in the project’s root directory (next to package.json, where ‘ncu’ is being run), like so:

{
  "upgrade": true,
  "reject": [
    "mobx",
    "query-string"
  ]
}

Bugs Fixen

If you have the following issue ( see red message) by installing the package with the new version : “Could not resolve dependency: npm ERR! …. “

that is how, you can fix it :

npm install --legacy-peer-deps

By Shabazz

Software Engineer, MCSD, Web developer & Angular specialist

Leave a Reply

Your email address will not be published. Required fields are marked *