Build fails when trying to use latest Yarn v 3.0.2

I am trying to upgrade my project to use the latest yarn (v3.0.2) and I see Netlify build is failing.

10:54:11 PM: Build ready to start
10:54:13 PM: build-image version: 3bcb38c35508b42e9121d4badfe6d8c66fd7a3f0
10:54:13 PM: build-image tag: v4.3.2
10:54:13 PM: buildbot version: 39428daf62968de16b6279e22b981b8b656d5e02
10:54:13 PM: Fetching cached dependencies
10:54:13 PM: Failed to fetch cache, continuing with build
10:54:13 PM: Starting to prepare the repo for build
10:54:14 PM: No cached dependencies found. Cloning fresh repo
10:54:14 PM: git clone https://github.com/SapneshNaik/kerneldev-website
10:54:17 PM: Preparing Git Reference refs/heads/staging
10:54:18 PM: Parsing package.json dependencies
10:54:18 PM: Different build command detected, going to use the one specified in the Netlify configuration file: ‘gatsby build && rm -rf public/.js public/.map public/.json public/page-data/’ versus 'gatsby build && rm -rf public/.js public/page-data/’ in the Netlify UI
10:54:19 PM: Starting build script
10:54:19 PM: Installing dependencies
10:54:19 PM: Python version set to 2.7
10:54:19 PM: Attempting node version ‘v14.18.0’ from .nvmrc
10:54:19 PM: Downloading and installing node v14.18.0…
10:54:20 PM: Downloading https://nodejs.org/dist/v14.18.0/node-v14.18.0-linux-x64.tar.xz
10:54:20 PM: Computing checksum with sha256sum
10:54:20 PM: Checksums matched!
10:54:23 PM: Now using node v14.18.0 (npm v6.14.15)
10:54:23 PM: Started restoring cached build plugins
10:54:23 PM: Finished restoring cached build plugins
10:54:24 PM: Attempting ruby version 2.7.1, read from environment
10:54:25 PM: Required ruby-2.7.1 is not installed - installing.
10:54:25 PM: Searching for binary rubies, this might take some time.
10:54:25 PM: Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-2.7.1.tar.bz2
10:54:25 PM: Checking requirements for ubuntu.
10:54:26 PM: Requirements installation successful.
10:54:26 PM: ruby-2.7.1 - #configure
10:54:26 PM: ruby-2.7.1 - #download
10:54:27 PM: ruby-2.7.1 - #validate archive
10:54:32 PM: ruby-2.7.1 - #extract
10:54:34 PM: ruby-2.7.1 - #validate binary
10:54:35 PM: ruby-2.7.1 - #setup
10:54:35 PM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1@global
10:54:35 PM: ruby-2.7.1 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems…
10:54:36 PM: ruby-2.7.1 - #generating global wrappers…
10:54:36 PM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1
10:54:36 PM: ruby-2.7.1 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
10:54:36 PM: ruby-2.7.1 - #generating default wrappers…
10:54:37 PM: Using /opt/buildhome/.rvm/gems/ruby-2.7.1
10:54:37 PM: Using ruby version 2.7.1
10:54:37 PM: Using PHP version 8.0
10:54:38 PM: Started restoring cached yarn cache
10:54:38 PM: Finished restoring cached yarn cache
10:54:38 PM: Installing yarn at version 1.22.5
10:54:38 PM: Installing Yarn!
10:54:38 PM: > Downloading tarball…
10:54:38 PM: [1/2]: https://yarnpkg.com/downloads/1.22.5/yarn-v1.22.5.tar.gz → /tmp/yarn.tar.gz.NQIWnk9VTv
10:54:38 PM: % Total % Received % Xferd Average Speed Time Time Time Current
10:54:38 PM: Dload Upload Total Spent Left Speed
10:54:38 PM: 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
10:54:38 PM: 100 79 100 79 0 0 686 0 --:–:-- --:–:-- --:–:-- 686
10:54:38 PM: 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
10:54:38 PM: 100 93 100 93 0 0 284 0 --:–:-- --:–:-- --:–:-- 592
10:54:38 PM: 100 625 100 625 0 0 1307 0 --:–:-- --:–:-- --:–:-- 1307
10:54:38 PM: 100 1215k 100 1215k 0 0 1960k 0 --:–:-- --:–:-- --:–:-- 1960k
10:54:38 PM: [2/2]: https://yarnpkg.com/downloads/1.22.5/yarn-v1.22.5.tar.gz.asc → /tmp/yarn.tar.gz.NQIWnk9VTv.asc
10:54:38 PM: % Total % Received % Xferd Average Speed Time Time Time Current
10:54:38 PM: Dload Upload Total Spent Left Speed
10:54:38 PM: 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
10:54:38 PM: 100 83 100 83 0 0 932 0 --:–:-- --:–:-- --:–:-- 932
10:54:38 PM: 100 97 100 97 0 0 822 0 --:–:-- --:–:-- --:–:-- 822
10:54:38 PM: 100 629 100 629 0 0 3145 0 --:–:-- --:–:-- --:–:-- 3145
10:54:38 PM: 100 832 100 832 0 0 3275 0 --:–:-- --:–:-- --:–:-- 3275
10:54:38 PM: > Verifying integrity…
10:54:38 PM: gpg: Signature made Thu 27 Aug 2020 11:16:49 AM UTC
10:54:38 PM: gpg: using RSA key 6D98490C6F1ACDDD448E45954F77679369475BAA
10:54:38 PM: gpg: Good signature from “Yarn Packaging yarn@dan.cx” [unknown]
10:54:38 PM: gpg: WARNING: This key is not certified with a trusted signature!
10:54:38 PM: gpg: There is no indication that the signature belongs to the owner.
10:54:38 PM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907 BBB7 1646 B01B 86E5 0310
10:54:38 PM: Subkey fingerprint: 6D98 490C 6F1A CDDD 448E 4595 4F77 6793 6947 5BAA
10:54:38 PM: > GPG signature looks good
10:54:38 PM: > Extracting to ~/.yarn…
10:54:38 PM: > Adding to $PATH…
10:54:39 PM: > Successfully installed Yarn 1.22.5! Please open another terminal where the yarn command will now be available.
10:54:39 PM: No yarn workspaces detected
10:54:39 PM: Started restoring cached node modules
10:54:39 PM: Finished restoring cached node modules
10:54:40 PM: Installing NPM modules using Yarn version 3.0.2
10:54:40 PM: Unknown Syntax Error: Unsupported option name (“–no-ignore-optional”).
10:54:40 PM: $ yarn install [–json] [–immutable] [–immutable-cache] [–check-cache] [–inline-builds] [–mode #0]
10:54:41 PM: Error during Yarn install
10:54:41 PM: Build was terminated: Build script returned non-zero exit code: 1
10:54:41 PM: Creating deploy upload records
10:54:41 PM: Failing build: Failed to build site
10:54:41 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 1
10:54:41 PM: Finished processing build request in 27.65721164s

I have figured out that the error " Unknown Syntax Error: Unsupported option name (“–no-ignore-optional”)." occurs because Yarn 3.0.2 no longer supports the --no-ignore-optional option. I’m not sure how Netlify is using this flag or where to unset it in Netlify.

Here is a GitHub issue on yarn berry that says yarn no longer supports this option. What happen to --ignore-optional? · Discussion #2412 · yarnpkg/berry · GitHub

I was able to reproduce this issue on my local system with yarn 3.0.2 by running yarn install --ignore-optional

Now, where can I change this in Netlify so that option is not used during Netlify build?

1 Like

Hi @SapneshNaik,

I’m a a little confused.

Here I see Yarn 1 is being installed.

But suddenly, I see Yarn 3 being used.

How’s that happening?

Same happens to me.
It seems to try and find yarn at

> Failed to download https://yarnpkg.com/downloads/3.0.2/yarn-v3.0.2.tar.gz

But it’s not there.

I am switching to classic v1.22.15 for now.

Hi @ilyafefelov,

Your issue seems different than the actual post.

However, based on this: Yarn 3 workspaces are not cached at all · Issue #615 · netlify/build-image · GitHub, Yarn 3.0.1 works. Does that work for you?