Yarn install failing node orb

When using the circleci/node orb, installing yarn using the install-yarn: true flag fails with the following error log

119
#!/bin/bash --login -o pipefail
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi

# FUNCTIONS
get_yarn_version () {
  if [[ "1.22.10" == "" ]]; then
    YARN_ORB_VERSION=$(curl -Ls -o /dev/null -w %{url_effective} \
      "https://github.com/yarnpkg/yarn/releases/latest" | sed 's:.*/::' | cut -d 'v' -f 2 | cut -d 'v' -f 2)
    echo "Latest version of Yarn is $YARN_ORB_VERSION"
  else
    YARN_ORB_VERSION=1.22.10

    echo "Selected version of Yarn is $YARN_ORB_VERSION"
  fi
}

installation_check () {
  echo "Checking if YARN is already installed..."
  if command -v yarn > /dev/null 2>&1; then
    if yarn --version | grep "$YARN_ORB_VERSION" > /dev/null 2>&1; then
      echo "Yarn $YARN_ORB_VERSION is already installed"
      exit 0
    else
      echo "A different version of Yarn is installed ($(yarn --version)); removing it"

      if uname -a | grep Darwin > /dev/null 2>&1; then
        brew uninstall yarn > /dev/null 2>&1
      elif cat /etc/issue | grep Alpine > /dev/null 2>&1; then
        apk del yarn > /dev/null 2>&1
      elif cat /etc/issue | grep Debian > /dev/null 2>&1; then
        $SUDO apt-get remove yarn > /dev/null 2>&1 && \
          $SUDO apt-get purge yarn > /dev/null 2>&1
      elif cat /etc/issue | grep Ubuntu > /dev/null 2>&1; then
        $SUDO apt-get remove yarn > /dev/null 2>&1 && \
          $SUDO apt-get purge yarn > /dev/null 2>&1
      elif command -v yum > /dev/null 2>&1; then
        yum remove yarn > /dev/null 2>&1
      fi

      $SUDO rm -rf "$HOME/.yarn" > /dev/null 2>&1
      $SUDO rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg > /dev/null 2>&1
    fi
  fi
}

get_yarn_version
installation_check

# install yarn
echo "Installing YARN v$YARN_ORB_VERSION"
curl -L -o yarn.tar.gz --silent "https://yarnpkg.com/downloads/$YARN_ORB_VERSION/yarn-v$YARN_ORB_VERSION.tar.gz"

$SUDO tar -xzf yarn.tar.gz && rm yarn.tar.gz

$SUDO mkdir -p /opt/yarn
$SUDO mv yarn-v${YARN_ORB_VERSION}/* /opt/yarn

$SUDO rm -rf "yarn-v${YARN_ORB_VERSION}"

$SUDO chmod 777 "/opt/yarn"

$SUDO ln -s /opt/yarn/bin/yarn /usr/local/bin/yarn
$SUDO ln -s /opt/yarn/bin/yarnpkg /usr/local/bin/yarnpkg
$SUDO ln -s /opt/yarn/bin/yarn.js /usr/local/bin/yarn.js

$SUDO mkdir -p ~/.config

if uname -a | grep Darwin; then
  $SUDO chown -R "$USER:$GROUP" ~/.config
  $SUDO chown -R "$USER:$GROUP" /opt/yarn
else
  $SUDO chown -R "$(whoami):$(whoami)" /opt/yarn
  $SUDO chown -R "$(whoami):$(whoami)" ~/.config
fi

# test/verify version
echo "Verifying YARN install"
if yarn --version | grep "$YARN_ORB_VERSION" > /dev/null 2>&1; then
  echo "Success! Yarn $(yarn --version) has been installed to $(which yarn)"
else
  echo "Something went wrong; the specified version of Yarn could not be installed"
  exit 1
fi

Selected version of Yarn is 1.22.10
Checking if YARN is already installed...
Error: EACCES: permission denied, open '/Users/distiller/.config/yarn'
    at Object.openSync (fs.js:462:3)
    at readFileSync (fs.js:364:35)
    at /usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:101332:58
    at Array.map (<anonymous>)
    at parseRcPaths (/usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:101330:78)
    at Object.findRc (/usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:101344:10)
    at getRcConfigForCwd (/usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:56916:74)
    at /usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:92695:56
    at Generator.next (<anonymous>)
    at step (/usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:310:30)
Error: EACCES: permission denied, open '/Users/distiller/.config/yarn'
    at Object.openSync (fs.js:462:3)
    at readFileSync (fs.js:364:35)
    at /usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:101332:58
    at Array.map (<anonymous>)
    at parseRcPaths (/usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:101330:78)
    at Object.findRc (/usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:101344:10)
    at getRcConfigForCwd (/usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:56916:74)
    at /usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:92695:56
    at Generator.next (<anonymous>)
    at step (/usr/local/Cellar/yarn/1.22.10/libexec/lib/cli.js:310:30)
A different version of Yarn is installed (); removing it
Installing YARN v1.22.10
tar: Error opening archive: Failed to open 'yarn.tar.gz'
mv: rename yarn-v1.22.10/* to /opt/yarn/*: No such file or directory
Darwin static.162.252.208.45.cyberlynk.net 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64
Verifying YARN install
/bin/bash: line 76: yarn: command not found
Something went wrong; the specified version of Yarn could not be installed
1 Like

Upon further investigation and running the step through ssh, I was able to find out that the circleci machine couldnt resolve the https certificate when downloading the yarn .tar.gz file

distiller$ curl -L -o yarn.tar.gz "https://yarnpkg.com/downloads/$YARN_ORB_VERSION/yarn-v$YARN_ORB_VERSION.tar.gz"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    81  100    81    0     0    591      0 --:--:-- --:--:-- --:--:--   591
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (60) SSL certificate problem: certificate has expired
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

How the heck am I supposed to fix something like this.

1 Like

Iā€™m having the same issue.

We fixed it by adding a step in the CI config file:

name: "Turn on insecure mode for curl"
command: echo insecure >> $HOME/.curlrc

This sets an alias for curl to always ignore the SSL