user
How can I update each dependency in package.json to the latest version?
alphonsio
npm i -g npm-check-updates
ncu -u
npm install

To update each dependency in your package.json to the latest version, you have a few options depending on your workflow and how aggressive you want the updates to be.


Option 1: Manually Update via CLI

1. Update all packages to the latest versions (including breaking changes)

You can use the npm-check-updates tool:

# Install globally if not already installed
npm install -g npm-check-updates

# Check for latest versions
ncu

# Upgrade package.json dependencies to the latest versions
ncu -u

# Install updated dependencies
npm install

Option 2: Update Using Built-in npm Commands

# This updates packages to the latest **compatible** versions based on the existing semver ranges.
npm update

If you want to update to the absolute latest versions (possibly including breaking changes), you'll need to change the version ranges in package.json manually or use ncu as above.


Option 3: Manually Edit package.json

You can directly change each version to:

"some-package": "latest"

Or even:

"some-package": "^latest_version"

Then run:

npm install

This is not recommended for large projects unless you know exactly what you're updating, as it can introduce breaking changes.


🧹 After Updating

After updating, always:

  1. Run your tests.
  2. Check for breaking changes in major version bumps.
  3. Review your lock file (package-lock.json or yarn.lock).