'Yarn - How do I update each dependency in package.json to the latest version?
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.
Solution 1:[1]
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
.
Solution 2:[2]
You can upgrade a single package to the latest major version with this:
yarn upgrade <package-name> --latest
Solution 3:[3]
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
Solution 4:[4]
The one that worked for me is from a comment by @Andrew Zolotarev, which uses
npx yarn-upgrade-all
Solution 5:[5]
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
Solution 6:[6]
If you want to update packages with yarn and update the package.json accordingly,
- Install syncyarnlock -
yarn global add syncyarnlock
- Update packages -
yarn upgrade
oryarn upgrade --latest
- Sync updated versions of yarn.lock to package.json -
syncyarnlock -s
Solution 7:[7]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Jeremy Caney |
Solution 3 | Ahmed Mokhtar |
Solution 4 | Jeremy Caney |
Solution 5 | Amr |
Solution 6 | Arosha |
Solution 7 | Ali Fensome |