How can I update each dependency in package.json to the latest version?

Better Stack Team
Updated on March 11, 2024

To update each dependency in package.json to the latest version, you can use the npm-check-updates package. Here are the steps:

  1. Install the npm-check-updates package globally by running the following command:
 
npm install -g npm-check-updates
  1. Run the following command to update the package.json file:
 
ncu -u

This command will update all dependencies in package.json to their latest version. It will also update the version numbers in package-lock.json or yarn.lock, depending on which package manager you are using.

  1. Run the following command to install the updated dependencies:
 
npm install

That’s it! Your dependencies should now be updated to the latest version.

Note: This might break some of your APIs. For example, if your package.json has webpack version 1, updating it to the latest version might break your build. Therefore, it’s important to test your application thoroughly after updating your dependencies.