84

I have a package and I want to downgrade the version use. How can I do this with yarn "dependencies"?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Emre
  • 951
  • 1
  • 5
  • 7

3 Answers3

82
Yarn version Command Example
1 yarn upgrade package@version yarn upgrade luxon@^3.0.1
2, 3 yarn up package@version yarn up luxon@^3.0.1
  • Use yarn -v to check your Yarn version.
  • Though the command is upgrade, it can be used for downgrading too.
Andrew Lam
  • 3,675
  • 4
  • 23
  • 34
hartshoj
  • 1,053
  • 7
  • 12
26

This is the official documentation https://classic.yarnpkg.com/en/docs/cli/upgrade There is no keyword for downgrading to a specific version.you have to use the upgrade keyword for both

yarn upgrade package@version

For example

yarn upgrade @types/express-session@^1.15.16 
Vimal Raj
  • 474
  • 6
  • 19
11

You can upgrade/downgrade a package interactively like so:

yarn upgrade my_package@^

This will produce an interactive list of available versions for the package for you to choose from. Like so:

Couldn't find any versions for "my_package" that matches "^"
? Please choose a version of "my_package" from this list: (Use arrow keys)
❯ 0.10.1
  0.10.0
  0.9.3
  0.9.2
  0.9.1
  0.9.0
  0.8.2
  0.8.0

One advantage of this method over using the upgrade-interactive keyword is that this produces an interactive list no matter what. While upgrade-interactive only gives you a list if your package is out of date. Thus, you can't always downgrade using the upgrade-interactive keyword.

Emanuel Lindström
  • 1,607
  • 16
  • 25
  • This results in the message "More?" which is completely incomprehensible – Hammerite Sep 22 '22 at 15:49
  • 1
    There's no reason to cause an error to upgrade a package interactively. You can just use `yarn upgrade-interactive my_package`. You can also use the `--latest` parameter to bypass the version limit configured on `package.json`, if necessary. – Cobra May 31 '23 at 14:16
  • 1
    @Cobra That doesn't work if you want to downgrade. `upgrade-interactive` will only work on packages that are out of date. As the documentation says: `yarn upgrade-interactive displays the outdated package list and lets you immediately chose which to upgrade` My method will always give you an interactive list. Thus, also allowing you to downgrade packages. – Emanuel Lindström Jun 01 '23 at 08:26
  • @EmanuelLindström True. I honestly didn't even notice that the text of the question mentioned only downgrading, I was going by the title. – Cobra Jun 03 '23 at 16:21