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?

1 Like

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" }
1 Like

That did it! Thank you so much!

1 Like