What do we know as Yarn 2?
It’s the modern version of Yarn that comes with important upgrades to the package manager including PNMP-style symlinks, and an innovative new Plug ‘n’ Play module installation method for much-reduced project sizes and rapid installations.
But after migrating from Yarn 1, you’ll find something interesting, as I did – the thing widely known as Yarn 2 is actually… version 3?
Why is “Yarn 2” using version 3?
It’s because Yarn 1 served as the initial codebase which was completely overhauled in the Yarn v2.0 (the actual version 2), enhancing its efficiency and effectiveness, with its launch taking place in January 2020. As time moved on, the introduction of a fresh major, Yarn v3.0, happened, thankfully without the need for another codebase rewrite. The upcoming major update is expected to be Yarn v4.0, and so on.
Despite the historical tendency of releasing few major updates, there was a growing trend among some individuals to label everything that used the new codebase as “Yarn 2”, which includes Yarn 2.x versions and future ones such as 3.x. This, however, was a misinterpretation as “Yarn 2” strictly refers to the 2.x versions. A more accurate way to reference the new codebase would be “Yarn 2+” or “Yarn Berry” – a codename that the team selected for the new codebase when they started developing it.
As once stated by one of the maintainers in a related GitHub discussion:
Some people have started to colloquially call “Yarn 2” everything using this new codebase, so Yarn 2.x and beyond (including 3.x). This is incorrect though (“Yarn 2” is really just 2.x), and a better term to refer to the new codebase would be Yarn 2+, or Yarn Berry (which is the codename I picked for the new codebase when I started working on it).arcanis, a Yarn maintainer
How to migrate from Yarn v1 to Yarn Berry
If you’re still using Yarn version 1 – or worse, NPM – you’re missing out.
The new Yarn is loaded with a sizable number of upgrades that will significantly improve your developer experience when you start using it. These range from notable improvements in stability, flexibility, and extensibility, to brand new features, like Constraints.
You can migrate from Yarn v1 to Yarn Berry in 7 easy steps:
- Make sure you’re using Node version 18+.
corepack enableto activate Corepack.
- Navigate to your project directory.
yarn set version berry.
- Convert your
.yarnrcfiles into .yarnrc.yml (as explained here).
yarn installto migrate the lockfile.
- Commit all changes.
In case you experience any issues due to breaking changes, this official Yarn Berry migration guide should help.
The Yarn versioning saga teaches us an important lesson: terminology matters.
What many of us dub as “Yarn 2” is actually “Yarn 2+” or “Yarn Berry”, the game-changing codebase. This misnomer emphasizes our need to stay current, not just with evolving tools and features, but with their rightful names as well. After all, how we understand and converse about these improvements shapes our effectiveness and fluency as developers.