Skip to content

Instantly share code, notes, and snippets.

@wojtekmaj
Last active May 4, 2024 00:32
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save wojtekmaj/c38351dd715c1b108ab1ab089fcaf6fc to your computer and use it in GitHub Desktop.
Save wojtekmaj/c38351dd715c1b108ab1ab089fcaf6fc to your computer and use it in GitHub Desktop.
How to upgrade Yarn to Yarn Modern (v4 at the moment) seamlessly
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
#!/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"
@MateoWartelle
Copy link

Thanks

@Grendel
Copy link

Grendel commented Oct 17, 2023

Yes - nice cheat sheet. Much appreciated.

@jacobwegner
Copy link

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.

@haki-user
Copy link

Your gist seems to be exactly what I needed. Appreciate you sharing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment