Last active
September 21, 2025 08:41
-
-
Save wojtekmaj/c38351dd715c1b108ab1ab089fcaf6fc to your computer and use it in GitHub Desktop.
How to upgrade Yarn to Yarn Modern (v4 at the moment) seamlessly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .yarn/* | |
| !.yarn/releases | |
| !.yarn/plugins |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Upgrade Yarn to Berry (latest Yarn 2 version known to Yarn 1) | |
| yarn set version berry | |
| # Upgrade Yarn Berry to latest version now that Yarn knows where to download it from | |
| yarn set version latest | |
| # (optional) Set nodeLinker to node-modules - this 100% guarantees backwards compatibility | |
| yarn config set nodeLinker node-modules | |
| # (optional) Adds `yarn upgrade-interactive` command back | |
| yarn plugin import interactive-tools | |
| # Reinstalls project using Yarn 2. This will also update your yarn.lock file, but will NOT sneakily upgrade the dependencies | |
| yarn | |
| # Commits the changes | |
| git add . && git commit -m "Upgrade Yarn to Yarn Berry (v2)" |
Yes - nice cheat sheet. Much appreciated.
Thanks for the Gist!
I was upgrading from Yarn 1.x on a Node 12 project and got this message:
yarn set version stable
➤ YN0000: Retrieving https://repo.yarnpkg.com/4.0.0/packages/yarnpkg-cli/bin/yarn.js
➤ YN0001: Error: Invalid semver version. yarn --version returned:
I instead set an explicit version (h/t https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=995073):
yarn set version 2.4.2
That helped me make it the rest of the way.
Your gist seems to be exactly what I needed. Appreciate you sharing it
Thank you! It worked well for me upgrading from 3.3.1 to 4.6.0.
worked well for me upgrading from yarn 1 to 4.6.0 except for this step
yarn plugin import interactive-tools
Author
@dominicgan Importing this plugin is no longer necessary in v4. They are now all built in.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks