163

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
  • 11,809
  • 11
  • 68
  • 98
  • 1
    [npm-check-updates](https://github.com/raineorshine/npm-check-updates) is fully compatible with yarn. Just run `npx npm-check-updates` in your project directory. – Raine Revere Jul 12 '22 at 14:49

13 Answers13

243

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.

Vahid Alimohamadi
  • 4,900
  • 2
  • 22
  • 37
75

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

yarn upgrade <package-name> --latest
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Favour George
  • 1,525
  • 13
  • 18
54

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-upgrade-all
b3hr4d
  • 4,012
  • 1
  • 11
  • 24
Ahmed Mokhtar
  • 2,388
  • 1
  • 9
  • 19
  • 4
    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
  • 6
    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
  • 3
    `yarn yarn-upgrade-all` didn't work for me but `npx yarn-upgrade-all` worked. Thanks @AndrewZolotarev – trkaplan May 29 '21 at 08:50
  • 3
    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
  • 2
    `npx yarn-upgrade-all` – Guilherme Abacherli Nov 18 '21 at 16:22
  • He specifically said "newer (but *stable*) versions", which this does not - the result is similar to `yarn upgrade --latest`, which will also install breaking changes. I have not seen any command or tool that does what OP asked for. – mindplay.dk Jul 07 '22 at 09:07
19

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

npx yarn-upgrade-all
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Inventrohyder
  • 311
  • 2
  • 3
17

With Yarn v2 and v3 (Berry)

You have to install appropriate plugin first with:

yarn plugin import interactive-tools

and then execute

yarn upgrade-interactive

Source: https://yarnpkg.com/cli/upgrade-interactive

jmarceli
  • 19,102
  • 6
  • 69
  • 67
9

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

Ali Fensome
  • 440
  • 4
  • 7
9

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

Raine Revere
  • 30,985
  • 5
  • 40
  • 52
  • Why not: `yarn upgrade --latest` without needing to bother with an additional package installation – Eugene Jul 16 '22 at 21:49
  • @Eugene because no one understands what "yarn upgrade --latest" actually does. For example, I have "hardhat": "^2.9.5" in my package.json, and would expect yarn upgrade --latest to change that to 2.10.1. But no. (It's probably a flag somewhere, may caret? Don't know, don't care.) It did update other things though. ncu just does the sensible thing. – James Moore Aug 11 '22 at 16:37
4

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
  • 1,311
  • 2
  • 16
  • 22
  • note that you will need to run `yarn install` again as the last step - it won't do anything other than update `yarn.lock` again, but if you don't do this, `yarn` will complain later that the version constraints that were *used* when `yarn.lock` was generated are now out of date. – mindplay.dk Jul 07 '22 at 09:36
3

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
  • 433
  • 5
  • 12
1

Update dependencies to latest versions, using jq:

jq '.dependencies | keys | .[]' package.json | xargs yarn add

Update dev dependencies to latest versions:

jq '.devDependencies | keys | .[]' package.json | xargs yarn add --dev
Pere
  • 1,647
  • 3
  • 27
  • 52
0

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

yarn up --interactive 

For more details in the official docs.

DevLoverUmar
  • 11,809
  • 11
  • 68
  • 98
  • 1
    I don't understand the design decisions in yarn up. For example, the latest hardhat version is 2.9.9. I have "hardhat": "^2.9.5" specified in package.json. You would expect yarn up --interactive would change 2.9.5 to 2.9.9, but instead it does nothing. The documentation talks about design decisions involving flags like caret, tilde, and exact; I didn't think it was worth bothering to figure out how those worked. ncu, on the other hand, does a useful thing in an obvious way. – James Moore Aug 11 '22 at 16:32
  • @JamesMoore you need a valid ```yarn.lock``` file before the upgrade operation. – Vahid Alimohamadi Oct 08 '22 at 21:33
  • @VahidAlimohamadi that just makes it worse. I'd expect "yarn up" to make changes to package.json whether or not there's a yarn.lock. Also, yarn.lock doesn't appear in the documentation for yarn up; that seems bad. – James Moore Oct 09 '22 at 00:59
  • 1
    @JamesMoore I'm not a YARN team member man! I just say it as a workaround! – Vahid Alimohamadi Oct 09 '22 at 07:32
  • This command does not relly work for me. I am using `yarn up --interactive "*"` – tmaier Jul 23 '23 at 07:03
0

If none of the answers worked for you, try to install again:

yarn add {PACKAGENAME HERE}

it will overwrite the current version to the latest version available

sFritsch09
  • 424
  • 4
  • 10
0

It can be done with --ignore-engines flag. So package installation will not fail due to an incompatible node version.

First run:

yarn --ignore-engines 
// This will install the older packages

And then:

yarn upgrade --ignore-engines 
// This will update packages to latest