7

I'm running a couple of projects that make use of Yarn v1 that will not be upgraded to Yarn v2 anytime soon for many reasons (CI being one of them). However, I would like to use Yarn v2 for new projects.

Is there a sane way to have both Yarn v1 and Yarn v2 installed on one machine so they can be used interchangebly between projects?

CoryCoolguy
  • 1,065
  • 8
  • 18
designorant
  • 2,344
  • 14
  • 25

1 Answers1

21

We recommend using Yarn 1 as global so as to avoid possible backward compatibility issues (for example later versions renamed some options and settings). You then have two options:

  • You can use yarn policies set-version berry on a per-project basis; it will install the very latest Yarn releases in the .yarn/releases folder, which you can then add to your repository. Docs for yarn policies.

  • Or you can add a "packageManager": "yarn@3.2.0" field to your package.json file and run corepack enable. This will use the Corepack tool to setup your system in such a way that any yarn commands will use the exact version you configured for the active project.

This keeps the risks to a minimum and allows you to migrate when you feel ready.

Maël Nison
  • 7,055
  • 7
  • 46
  • 77