How to update package.json

Running npm install on a fresh project installs the latest package versions and satisfies the semantic versioning ranges defined in the project’s package.json. After the initial install, re-running npm install will not update existing packages since npm will have already found satisfying versions of packages installed on the file system.

A package.json file:

  • Lists the packages that the project depends on.
  • Specifies versions of a package that the project can use with semantic versioning rules.

Updating packages to the most recent minor version

The procedure used to update the dependencies in the package.json file to the latest minor version is outlined here. However, this method leaves the package.json untouched.

Updating packages to the most recent major version

A user may want to update the dependencies specified in package.json to the latest major version if they are sure that the project will still work without breaking anything.

Doing so will update the version numbers specified in the ​front of each package, hence updating the project’s package.json file.

The correct way to do so is:

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

Now, all of the package versions in package.json will ​be the most recent ones.

Copyright ©2024 Educative, Inc. All rights reserved