Upgrading package(s) inYarn

Suman Kunwar
2 min readJun 29, 2022
Fig: Yarn Package Manager

Yarn is one of the promising package managers that provides a fast, reliable, and secure packaging system. It was created with the collaboration of tech giants such as Facebook, Google, Exponent, and Tilde and has been used by many developers.

Managing external packages can be troublesome over the course of time. This article guides on how to upgrade the packages using yarn as per one's need. yarn upgrade command updates the dependencies to their latest version as specified in their package.json file and the changes are also reflected in to yarn.lock file. Following are some of the ways to upgrade package(s) using yarn.

[package]: When a package name is specified only then it gets upgraded to the latest matching version.

[package@tag]: When a tag is specified then it gets upgraded to that specified tag. Tag names are usually created by maintainers to point to specific releases.

[package@version]: When a version is mentioned in a specified package then the specified version gets updated.
Examples:

yarn upgrade
yarn upgrade left-pad
yarn upgrade left-pad@^1.0.0
yarn upgrade left-pad grunt
yarn upgrade @angular

To upgrade all packages that match the pattern --pattern flag is used followed by the matching pattern (s).

yarn upgrade --pattern <pattern>

To get the latest version of the package one can pass a --latest flag.

yarn upgrade <packagename> --latest

To upgrade the package with a scope, --scope or -s flag can be passed with the upgrade syntax. A scope must begin with @ syntax.

yarn upgrade --scope @angular

If one is not sure of which package to upgrade, they can run the following command. It will give you the list of packages that has been updated with change info.

yarn upgrade-interactive

After upgrading, run yarn build and look for the deprecation messages in the build log. Follow instructions to fix those deprecations.

--

--

Suman Kunwar

Innovating Sustainability | Researcher | Author of Learn JavaScript : Beginners Edition