76

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.

DevLoverUmar
  • 8,356
  • 8
  • 44
  • 81

7 Answers7

130

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.

cybercoder
  • 3,545
  • 2
  • 18
  • 30
  • 3
    Clear your ```node_modules``` folder and ```yarn.lock``` , ```yarn-error.log``` files. Then try ```yarn --ignore-engines```. After successful instllations, try ```yarn upgrade-interactive --latest```. – cybercoder Jul 03 '20 at 06:30
  • 5
    If all of these had no success, then try ```yarn outdated``` and update packages directly manual in ```package.json``` one by one. You need to have relaxed mind before do that :) – cybercoder Jul 03 '20 at 06:34
  • 1
    Loved the `yarn outdated` as this seems more logical to do if got a long list of deps :) – just-be-weird Oct 17 '21 at 11:42
  • 1
    It's `yarn up` for the modern version of Yarn https://yarnpkg.com/cli/up – Daria Apr 21 '22 at 13:37
36

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

yarn upgrade <package-name> --latest
Jeremy Caney
  • 6,191
  • 35
  • 44
  • 70
Favour George
  • 1,067
  • 11
  • 15
  • 2
    You want him to go one by one and list all his packages? – Davo Nov 24 '21 at 00:54
  • 8
    Sometimes you want to only update a single dependency. For updating the patch version (major.minor.patch), you can use e.g. yarn upgrade @1.1.x (use whatever major/minor version you have) – zmx Dec 14 '21 at 08:55
  • 2
    @zmx is the best answer in this page. Upgrading an entire dependency may end up in a rabbit hole, and unfortunately the other suggestions don't always work. – Miguel Mar 22 '22 at 21:49
  • 1
    This answer is wrong--this command does not update the package.json with the latest version. – wheeler Apr 23 '22 at 04:25
28

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
Ahmed Mokhtar
  • 1,998
  • 8
  • 18
  • 3
    Thanks! Its a good option with only one caution. From official docs "Don't use yarn to install it on Windows because there is a bug https://github.com/yarnpkg/yarn/issues/2224" – DevLoverUmar Jul 08 '20 at 18:29
  • 4
    This package runs `yarn remove && yarn add` for all packages in `package.json` Too slow, but works! Shorter version: `npx yarn-upgrade-all` – Andrew Zolotarev Jan 26 '21 at 19:46
  • 2
    `yarn yarn-upgrade-all` didn't work for me but `npx yarn-upgrade-all` worked. Thanks @AndrewZolotarev – trkaplan May 29 '21 at 08:50
  • 1
    Running `npx yarn-upgrade-all` changed my `"vue": "^3.0.5"` dependency to `"vue": "^2.6.14"` which I did not expect. Obviously, this broke the build. – Glenn Jun 22 '21 at 13:59
  • 1
    `npx yarn-upgrade-all` – Guilherme Abacherli Nov 18 '21 at 16:22
6

The one that worked for me is from a comment by @Andrew Zolotarev, which uses

npx yarn-upgrade-all
Jeremy Caney
  • 6,191
  • 35
  • 44
  • 70
Inventrohyder
  • 81
  • 1
  • 2
2

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
Arosha
  • 873
  • 2
  • 9
  • 20
1

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
Amr
  • 147
  • 2
  • 10
1

List outdated

yarn outdated

Upgrade all dependencies

yarn upgrade --latest

Yarn docs