Using the new yarn release (2.0.0 / berry)

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