Last active
March 13, 2025 21:30
-
-
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 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
.pnp.* | |
.yarn/* | |
!.yarn/patches | |
!.yarn/plugins | |
!.yarn/releases | |
!.yarn/sdks | |
!.yarn/versions |
This file contains 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 to latest Yarn Modern (v4 at the moment) | |
# WARNING: If you're running Node.js < 18: | |
# 1. Who hurt you? | |
# 2. Use `yarn set version 3.6.4` instead. | |
yarn set version berry | |
# (optional) Set nodeLinker to node-modules - this 100% guarantees backwards compatibility | |
# NOTE: Not needed in latest Yarn versions, this should be automatic | |
yarn config set nodeLinker node-modules | |
# (optional) Adds `yarn upgrade-interactive` command back | |
# NOTE: Not needed in Yarn v4, plugins are now included | |
yarn plugin import interactive-tools | |
# Reinstalls project using Yarn Modern. 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" |
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
@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