Cache YARN properly?



I’m following all of the instructions from

I still see yarn install every time (first non-cached issue), and then I still see all the node modules being downloaded every time by yearn (second non-cached issue).

I expected:

  • Yarn would be cached due to my cache-directories setting.
  • Node modules would not be downloaded since yarn (locally) never downloads files twice.

Please advise, thanks.

Yarn caching in 2.0

There is an existing feature request to have Yarn preinstalled, please :heart: that post as that is how the product team gauges interest and prioritizes requests.

Regarding the issue of caching the Yarn packages, adding the following snippets to your circle.yml file will resolve that:

    - mkdir ~/.yarn-cache


    - ~/.yarn-cache

Please keep in mind that this will increase your Restore Cache step, so you may want to do a couple tests to see which is faster.

To explain, we need to create the ~/.yarn-cache directory before the dependencies, as you can not tell CircleCi to cache a directory that does not exist at the time the instruction is parsed.

Preinstall Yarn

Worked like a charm, and thanks for the informative answer, you guys rock!


I updated the gist in the guide as well. Cheers!



I’ve tried following these instructions, but yarn does a full install every time I run a build. I can ssh onto the box during the build and confirm that the yarn cache is properly restored. However, running yarn install always does a fresh install the first time it is run as part of the build. If i run it a second time during the build it correctly reads from the cache. There is nothing unique about my setup afaik. Below is the relevant section of my circle.yml file.

    - mkdir ~/.yarn-cache
    version: 5.0.0
    version: 2.3.1
    - curl -o- -L | bash
    - mkdir -p tmp/cache/assets/production
    # Global node_modules
    - "~/nvm/versions/node/v5.0.0/bin"
    - "~/nvm/versions/node/v5.0.0/lib/node_modules"
    # yarn cache
    - ~/.yarn-cache
    # Application sprockets compiled assets
    - "tmp/cache/assets/production"
    - yarn install
    - bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
    - NODE_ENV=production yarn run build


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


Have others seen issues with yarn install failing due to caching issues?

This tends to happen when a package changes and often it only happens on one of our environments. recently it’s been, but not