Using the new yarn release (2.0.0 / berry)

Kia ora!

I’ve just updated my repo locally to use the new yarn - 2.0.0-rc.27 is what I have locally. I’ve tried to follow the guides about setting an environment variable to override Netlify’s default Yarn version, but keep running into issues.

Obviously, the environment variable wants a specific version number - major.minor.path. Including the rc.27 causes this to fail. Including just 2.0.0 gets a 404 from the curl script - which is perhaps just a breaking change on the yarnpkg website.

Has anyone been able to figure this out?

2 Likes

tl;dr: remove the YARN_VERSION env config from netlify.toml, check in the contents of .yarn/releases after installing yarn@berry and running yarn in your project, and have a .yarnrc file at the root of your repo, with the contents:

yarn-path ".yarn/releases/yarn-rc.js"

You can circumvent Netlify’s strict semver format here by specifying the yarnPath to the v2 release in the v1.17 format: yarn-path

When you run yarn install, yarn@berry adds itself to your repo (under .yarn/releases). You’re encouraged to check this directory into your project’s vcs, along with the .yarnrc.yml it seeds to contain a relative path to the new yarn “binary” release:

yarnPath: .yarn/releases/yarn-rc.js

In order to make this compatible with Netlify’s current build setup you’ll need to specify this relative path to the new release in the equivalent v1 format so that Netlify’s yarn@1.17.0 can bootstrap yarn@berry. Your .yarnrc should contain:

yarn-path ".yarn/releases/yarn-rc.js"

With this, you can remove any such changes to netlify.toml:

# Don't add this
[build]
  environment = { YARN_VERSION = "2.0.0-rc.28" }
3 Likes

That did it! Thank you so much!

1 Like

I’m using yarn@2.4.0 and the solution no longer works. This is my .yarnrc.yml file:

nodeLinker: "node-modules"
yarnPath: ".yarn/releases/yarn-berry.cjs"

Update: I managed to get it work aftet renaming the .yarnrc.yml configuration file to .yarnrc.

Update 2: Berry started malfunctioning, and I learned that .yarnrc is NOT equivalent to .yarnrc.yml. Yet, Netlify still requires the former to enable v2. So we need both an .yarnrc file and a .yarnrc.yml file.

1 Like

A problem for me is that it took me a while to double check that I had the right file linked, since yarn is specified as .yarn/releases/yarn-berry.cjs for me.

After realizing my different ways I failed to link it right, it finally worked for me!

2 Likes

What is the correct way to do this? I imagine that yarn has a way that it is meant to detect the correct version, right?

I had the fun problem of figuring out “why is netlify using yarn version berry when I’m using yarn version 3.0.0-rc.2?”, which happened because yarn set version 3.0.0-rc.2 only updated .yarnrc.yml and not .yarnrc since that is not a part of yarn berry.

Hey! Have you configured the env var as 3.0.0? I’m taking inspiration from this post from a little while ago though I assume things are the same today.

1 Like

It would be awesome if Netlify wouldn’t require “.yarnrc” for yarn berry! Took me a long time to find this information.

I tried that both with YARN_VERSION="3.0.0" and YARN_VERSION="3.0.0-rc2" but 3.0.0 doesn’t exist yet, and 3.0.0-rc2 “release candidate 2” is complained about because it doesn’t match x.x.x perfectly.

9:02:28 PM: Found yarn version (1.3.2) that doesn't match expected (3.0.0-rc2)
up to date in 0.029s
9:02:28 PM: Installing yarn at version 3.0.0-rc2
9:02:28 PM: Installing Yarn!
9:02:28 PM: > Downloading tarball...
9:02:28 PM: > Version number must match MAJOR.MINOR.PATCH.
9:02:28 PM: mv: cannot stat '/opt/buildhome/.yarn': No such file or directory

It seems after setting YARN_VERSION="2.0.0" it doesn’t support anything past Yarn 1 D:

So I’m currently setting YARN_VERSION="1.22.10", the latest Yarn 1.

Ah, my bad. Yeah, you’ll want to keep tabs on this for the time being!

1 Like

Yarn 3.0.0 is out! I’ll take a look at your link, it’d be great to get support somehow for yarn >1.0 :slight_smile: