Yarn - How do I update each dependency in package.json to the latest version?

Viewed 88394

I have a react app with deprecated dependencies. To make it work, I have to update the dependencies to their newer (but stable) versions.

As per this stakoverflow thread, to update dependencies in package.json to latest versions, npm-check-updates is the Best Option for npm. However, I'm using yarn for package management. Is there an equivalent of npm-check-updates in yarn. So that, I use a single package manager to manage my dependencies.

10 Answers

yarn upgrade-interactive --latest

But you have to have a yarn.lock file before do it. If you are using npm, you must delete package-lock.json first. Then run yarn to create structure. After that you can do upgrade-interactive. Without that, yarn shows upgrade, but no changes and effects in package.json.

You can upgrade a single package to the latest major version with this:

yarn upgrade <package-name> --latest

You can try this npm package yarn-upgrade-all. This package will remove every package in package.json and add it again which will update it to latest version.

installation:

npm install -g yarn-upgrade-all

usage: in your project directory run:

yarn yarn-upgrade-all

If you want to update packages with yarn and update the package.json accordingly,

  1. Install syncyarnlock - yarn global add syncyarnlock
  2. Update packages - yarn upgrade or yarn upgrade --latest
  3. Sync updated versions of yarn.lock to package.json - syncyarnlock -s

List outdated

yarn outdated

Upgrade all dependencies to latest

This will upgrade to the latest version, irrespective of if the package is stable or the versioning constraints between your packages.

yarn upgrade --latest

Yarn docs

In case you wanted to add the package to your package.json for development collaboration

yarn add yarn-upgrade-all -D
yarn yarn-upgrade-all

By the way, the package uses the command ( reinstall all packages again )

yarn install package1 package2 packageN

npm-check-updates is fully compatible with yarn. Just run npx npm-check-updates in your project directory.

npm-check-updates is a battle-tested, 8yr old library that just works. It offers interactive mode and doctor mode for automatically running tests and identifying broken upgrades.

Disclaimer: I am the main contributor of npm-check-updates.

npm-check-updates - default output

Interactive + Group mode:

npm-check-updates - interactive mode

For the latest versions of yarn (for me it's 3.2.2)

yarn up --interactive 

For more details in the official docs.

Related