Skip to content

Instantly share code, notes, and snippets.

@dennisreimann
Last active September 23, 2022 16:11
Show Gist options
  • Save dennisreimann/c2a6ef58544861f7e13762e06e146dac to your computer and use it in GitHub Desktop.
Save dennisreimann/c2a6ef58544861f7e13762e06e146dac to your computer and use it in GitHub Desktop.
Travis-CI config for Yarn 2
language: node_js
cache:
# Yarn 2 does not store dependencies in node_modules anymore, at least not by default.
# If you are using the node-modules plugin, remove the `npm: false` line.
npm: false
# Yarn 2 caches to the local .yarn directory, not the Travis default `$HOME/.yarn`
directories:
- ./.yarn/cache
before_install:
# Upgrade Yarn 1.x: https://classic.yarnpkg.com/en/docs/install
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH="$HOME/.yarn/bin:$PATH"
# Then the local Yarn 2 should be available and get used
- yarn -v
# Use custom install step as Travis by default uses the --frozen-lockfile flag, which is deprecated
install: yarn
# rest stays the same, hopefully …
@Super-Chama
Copy link

Thanks for this. This helped where official yarn or Travis docs didn't have any information regarding this. I encountered additional problems as Travis was having SSL certificate issues fetching yarn from the URL and yarnrc.yml file making more issues. I changed the before_install as follows and got it working.

before_install:
  - rm .yarnrc.yml
  # Repo for Yarn
  - sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
  - echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  - sudo apt-get update -qq
  - sudo apt-get install -y -qq yarn
  - yarn set version berry
  - export PATH="$HOME/.yarn/bin:$PATH"
  # Then the local Yarn 2 should be available and get used
  - yarn -v

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment