Preinstall Yarn

shipped
nodejs

#1

Yarn is a JS packager manager that is similar to the npm CLI program but much faster and more reliable. Yarn also supports offline installation of packages if your dependency tarballs are committed to Git, which is great for CI since tests and builds will succeed even if the npm registry goes down. It is shaping up to be pretty popular and got 7k stars and counting on GitHub under 24 hours.

Could CircleCI preinstall Yarn by default so everyone doesn’t need to install it manually?


Cache YARN properly?
Ng: command not found (angular-cli & yarn)
#2

Would love this. In CI, npm install times count a lot!


#3

+1 - I’m finding Yarn to be much quicker for installs than standard NPM.


#4

Agreed. However, even with having to install Yarn each time we’ve shaved minutes off our build times. I wrote a quick guide on how you can swap over to yarn.

https://medium.com/@ekryski/using-yarn-with-circleci-and-heroku-31d0d247bd59#.3j2fur63v


Yarn install hangs and never completes
#5

Great guide, thanks for writing it. Would you like to add in the steps to cache the ~/.yarn-cache directory?


#6

Done! I updated the gist in the guide.


#7

There’s some instructions on the Yarn site about how to use it on CircleCI (https://yarnpkg.com/en/docs/install_ci), but having Yarn preinstalled would be awesome :smiley:


#8

Here is what we’re doing:

Shell script to install specific version of npm or yarn.

shell file below is ./scripts/misc/installPackageManager

#!/bin/bash
set -e
set -o pipefail


# first, make sure you have latest npm/yarn

# if you want pure latest npm then `npm show npm version`
PM='yarn'
PM_VERSION='0.X'
LATEST_PACKAGE_MANAGER=`npm show $PM@$PM_VERSION version | tail -n 1 | awk '{print $2}'`
LATEST_PACKAGE_MANAGER=$(echo $LATEST_PACKAGE_MANAGER | sed "s/\'//g")
CURRENT_PACKAGE_MANAGER=`$PM --version` || CURRENT_PACKAGE_MANAGER=''

echo "latest $PM: $LATEST_PACKAGE_MANAGER"
echo "current $PM: $CURRENT_PACKAGE_MANAGER"
if [[ $LATEST_PACKAGE_MANAGER != $CURRENT_PACKAGE_MANAGER ]];then
  npm install -g $PM@$PM_VERSION
fi

Then in circle.yml

machine:
  pre:
    - mkdir ~/.yarn-cache
  node:
    version: v4.6.1

dependencies:
  override:
    - ./scripts/misc/installPackageManager && yarn install
  cache_directories:
    - ~/.yarn-cache

test:
  override:
    - yarn test


#9

Thanks so much for the suggestion and thank you to the community for the overwhelming feedback for this.

I am working with our image team to try to get this rolled out in the next image release. Hope to have an update for everyone here soon!


#10

This is something that we have rolled out, please see our docs for details.

https://circleci.com/docs/1.0/yarn/


#11

I don’t understand how this is simpler or more useful than the traditional hacky way. I really hoped that I could simply use yarn: true somewhere and override the dependencies & test sections with yarn install and yarn test. It’s still simpler to cache the yarn cache dir and install it by running sudo apt-get update && sudo apt-get install yarn which takes less than 10 seconds.


#12

Me neither, I was also under the impression that implementation would be that the inference things would see a yarn.lock and say, oh, do it the yarn way, … I’m going to do those yarn things.


#13

I’ve updated circle.yml as described, but it’s not working, since yarn command not found.

yarn install
bash: line 1: yarn: command not found

yarn install returned exit code 127

Action failed: yarn install

circle.yml: https://github.com/dialogs/dialog-web-components/blob/master/circle.yml


#14

Please check your Starting container step. You may be on our 12.04 build image, which we are no longer updating due to it being EOL very soon.


#15

Did you try removing your custom apt-get installation and rebuild without cache?


#16

I’ve added custom apt-get installation after posting problem here.


#17

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.