Yarn is not installed
We are using a self-hosted runner and using this action to setup-node and install yarn.
I know on github-hosted runners, yarn is already pre-installed but it would be good if yarn was installed by this action for those of us using self-hosted.
Running setup-node with the following workflow and it works
with:
node-version: 12.13.0
always-auth: true
registry-url: https://registry.npmjs.org
/usr/bin/tar xz --warning=no-unknown-keyword -C /actions-runner/_work/_temp/febce1c0-314e-4a14-9a65-5bde8a990b71 -f /actions-runner/_work/_temp/d4bf33ab-571e-458e-9495-bd6c5b994814
/actions-runner/_work/_tool/node/12.13.0/x64/bin/node --version
v12.13.0
/actions-runner/_work/_tool/node/12.13.0/x64/bin/npm --version
6.12.0
Note that node and npm are installed.
A later step in the workflow then attempts to run yarn:
Run yarn install --ignore-scripts --frozen-lockfile
/actions-runner/_work/_temp/58e53b82-f9ae-4c68-9cec-75f75831208b.sh: line 1: yarn: command not found
##[error]Process completed with exit code 127.
This of course works on github hosted runners just fine, but since I just migrated to an EC2 instance that doesn't have yarn installed, I am now having issues.
Workaround is to install yarn yourself using npm (after running this action)
- name: Install Yarn
run: npm install -g yarn
and later can uninstall it -
- name: Uninstall Yarn
if: always()
run: npm uninstall -g yarn
While this works, I find it rather hacky. It would be good for this action to not need to rely on github's instances to have yarn package installed.
EDIT:
I wanted to add the documentation acts as if yarn is a given, since it has sections on usage with yarn
Publish to npmjs and GPR with yarn:. Perhaps some clarification in that section that if you're on self-hosted runners you will need to install yarn yourself via npm install -g yarn and uninstall it at the end of your job with npm uninstall -g yarn
GitHub Runners creates a file called .path in the same directory where you have config.sh. It contains the content of $PATH variable, which is further used during the execution of your workflows.
You have to add a directory with the yarn binary. In my case:
/home/github/.yarn/bin`
@pperzyna thanks! I spent 30mins guessing why it was not working even after updating the path. Seems run.sh has to be restarted.
npm install -g yarn
Hey @GoldFlsh , why should we uninstall yarn at the end of a job?
@konsalex Since self-hosted runners are shared and are not a clean instance per job execution, like a github hosted runner would be, the job should do its best to clean itself up after a run so that each future workflow run is running on what amounts to a fresh instance.
If you install software during the run, such as yarn, redis, or terraform without uninstalling it, could potentially cause conflicts with other jobs running as the state of the instance moves further away from the original state.
Say then you try to upgrade versions of something in your workflow but since the old version is still installed from a previous run it may use that and create a difficult to debug situation.
As others have mentioned you can pre-install any software on a self-hosted runner so the workflow itself does not have to be responsible for installing anything, which would side-step this altogether.
Up to you, of course, how you best want to manage that 😃
https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners#differences-between-github-hosted-and-self-hosted-runners
Note that if you use with: cache: yarn this action will fail if you don't have yarn pre-installed... But since you need node to install yarn.. you can't get out of this without running this action twice or using other actions.
To +1 on Davide's comment, the lack of yarn install support is a significant obstacle to those of us on self-hosted runners.
The only way to break the chicken-or-egg with: cache: yarn problem, and make caching work on self-hosted runners, is to preinstall yarn on the runner base image (like GitHub does for its own runners). This is not good because then yarn is being managed both by setup-node, and out-of-band by the preinstall step.
Hi everyone. I faced the same problem and this may sound really stupid, but I solved it this way:
(Thanks for the tip, @davide-bertola-deltatre)
jobs:
node-ci:
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- name: Setup Nodejs and npm
uses: actions/setup-node@v2
with:
node-version: "14"
- name: Setup yarn
run: npm install -g yarn
- name: Setup Nodejs with yarn caching
uses: actions/setup-node@v2
with:
node-version: "14"
cache: yarn
- name: Install dependencies
run: yarn
NOTE: This way, if you run the yarn uninstall in the step, the Post process will not be able to find yarn and the job will fail.
Actions log shows that the cache was successful, but I am not sure if it is really cached in this case.
Cache Size: ~118 MB (124177777 B)
Cache saved successfully
Cache saved with the key: foo-bar-baz
When I connected to the runner instance that ran the job and ran the yarn command, I got not found, so everything seems to be working. However, this is not an essential solution and I also hope that yarn will be installed with it.
FYI: There isn't a chicken-and-egg problem, you don't need Node to install yarn:
curl -fsSL -o ~/bin/yarn \
https://github.com/yarnpkg/yarn/releases/download/v1.22.17/yarn-1.22.17.js
chmod +x ~/bin/yarn
I think the point of contention here is that we need to return the runner back clean. It's easy enough to install the binaries, but given the hassle of making sure they're purged every time, I'd prefer to see them included under Node's control
GitHub Runners creates a file called .path in the same directory where you have config.sh. It contains the content of
$PATHvariable, which is further used during the execution of your workflows.You have to add a directory with the yarn binary. In my case:
/home/github/.yarn/bin`
Thanks @pperzyna
Let me share my approach, maybe it will useful.
Find out where is the yarn
First on your server run:
which yarn
then you got the yarn location, like this
/home/admin/.nvm/versions/node/v16.14.0/bin/yarn
copy the path (not including the yarn)
/home/admin/.nvm/versions/node/v16.14.0/bin
Edit path
run
nano .path
you got something like
aaaaa:bbbb:cccc
separated with :
then paste the /home/admin/.nvm/versions/node/v16.14.0/bin
so the .path become
aaaaa:bbbb:cccc:/home/admin/.nvm/versions/node/v16.14.0/bin
Don't add the enter or something. Just give the : and paste next to it
Restart runner
You need restart it. so it will load the new path
Mostly you are running with svc.sh then stop it
sudo ./svc.sh stop
Run it again
sudo ./svc.sh start
While Node 17 isn't LTS, moving forward with Node 18 LTS (or >=16.10 LTS) it would be great if corepack enable was automatically run if the cache is yarn or pnpm.
Corepack is part of the node install itself and contains both yarn and pnpm but is currently opt-in. It's also the recommended way to use/install yarn 2+.
You can enable it manually in a single step which fixed the issue for me:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '17'
cache: 'yarn'
- run: corepack enable
- run: yarn install
- run: yarn lint
While Node 17 isn't LTS, moving forward with Node 18 LTS (or >=16.10 LTS) it would be great if
corepack enablewas automatically run if the cache is yarn or pnpm.Corepack is part of the node install itself and contains both yarn and pnpm but is currently opt-in. It's also the recommended way to use/install yarn 2+.
You can enable it manually in a single step which fixed the issue for me:
jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '17' cache: 'yarn' - run: corepack enable - run: yarn install - run: yarn lint
This doesn't solve this issue. It's only working for you because you're using runs-on: ubuntu-latest which has yarn installed by default.
I have the error yarn: command not found (just forked your repo on V3)
What is the best way to fix it ?
# Install node.js and yarn
- uses: Clovis-team/action-setup-node@v3
with:
node-version: '14'
# Get yarn cache directory path in order to cache it
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: |
echo "::set-output name=dir::$(yarn cache dir)"
echo "::set-output name=version::$(yarn -v)"
shell: bash
Log in github:
Run Clovis-team/action-setup-node@v3
Attempting to download 14...
Acquiring 14.20.0 - x64 from https://github.com/actions/node-versions/releases/download/14.20.0-2633808318/node-14.20.0-linux-x64.tar.gz
Extracting ...
/usr/bin/tar xz --strip 1 --warning=no-unknown-keyword -C /home/runner/_work/_temp/7bbe90d2-dc57-4b39-b61c-14fb1db60e4f -f /home/runner/_work/_temp/b4832165-c982-406d-bb25-e1f89e2a8268
Adding to the cache ...
Done
Run echo "::set-output name=dir::$(yarn cache dir)"
/home/runner/_work/_temp/a152258c-d989-400f-a9b8-abc6252b12b7.sh: line 1: yarn: command not found
/home/runner/_work/_temp/a152258c-d989-400f-a9b8-abc6252b12b7.sh: line 2: yarn: command not found
Hi, a lot of great answers here! Based on @jasonk's solution, to run setup-node on a self-hosted runner we're doing this (2023 edition):
...
- name: Install yarn
run: |-
curl -fsSL --create-dirs -o $HOME/bin/yarn \
https://github.com/yarnpkg/yarn/releases/download/v1.22.19/yarn-1.22.19.js
chmod +x $HOME/bin/yarn
echo "$HOME/bin" >> $GITHUB_PATH
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
...
Curl needs the --create-dirs option, otherwise it cannot write to a not-yet-existing directory and complains with (23) Failed writing body.
Also, you need to add whatever folder you're copying the yarn executable into to $GITHUB_PATH in order for setup-nodeto pick it up.
Let me get this straight, the solution is for the consumers to:
- download an orphaned yarn bin
- append the bin location to
$GITHUB_PATH- which will prove an agony if you hoped to at least keep that shit out of the workflow
- run
actions/setup-node - so that we can then exec
$ yarnThat's quite an amusing procedure, I admit. So, what about those who are not using or have migrated from the legacy obsolete, unmaintained, unsupported, ancient yarn 1.* (that luckily doesn't provide proper binaries for the last release, but rather the aforementioned orphaned bin we use as a workthefaroundabout) and have pretty much no choice but to use corepack - the official tool for managing node package managers - to install yarn? Are we gonna have to exploit quantum state to both install it and not install it for this shit to work, or we adding support for something that node took ownership of? It is not a separate concern anymore.
tldr. Anyways, done with the rant, debugging self-hosted runners combined with this, well, definitely doesn't qualify as fun. I'll put up a PR proposal for fixing this later/tomorrow, depending on how much of yarn installation control I end up having to expose.
Corepack & Yarn is a bad joke.
Prior to this yaml on node 20 use corepack use yarn@* to write e.. "packageManager": "[email protected]+sha256.825003a0f561ad09a3b1ac4a3b3ea6207af2796d54f62a9420520915721f5186", to package.json which is read by corepack install (it's not this on node 18.)
...
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
- run: |
corepack enable &&
corepack install # use the in-repo yarn version
- name: Setup Yarn in Node
uses: actions/setup-node@v4
with:
cache: "yarn" # uses the system node, which was updated prior.
...
Running into this issue in July 2024...
Current workaround:
vitest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'yarn'
# FIXME: Because the setup-node action is dumb, we have to manually
# install the dependencies ourselves. See: https://github.com/actions/setup-node/issues/182
- name: Install dependencies
run: yarn install
- name: Run tests
run: yarn test:unit:ci
Another workaround is to replace all calls to yarn with corepack yarn which has the additional benefit of knowing exactly which version you are using.
After upgrading to Node 22, corepack enable stopped working:
Internal Error: EACCES: permission denied, symlink '../lib/node_modules/corepack/dist/pnpm.js' -> '/opt/actions-runner/_work/_tool/node/22.11.0/x64/bin/pnpm'
at async Object.symlink (node:internal/fs/promises:1001:10)
at async EnableCommand.generatePosixLink (/opt/actions-runner/_work/_tool/node/22.[11](https://github.com/creditornot/converse-services/actions/runs/11659651461/job/32460569908#step:8:12).0/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:22608:5)
at async Promise.all (index 0)
at async EnableCommand.execute (/opt/actions-runner/_work/_tool/node/22.11.0/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:22595:5)
at async EnableCommand.validateAndExecute (/opt/actions-runner/_work/_tool/node/22.11.0/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:19835:22)
at async _Cli.run (/opt/actions-runner/_work/_tool/node/22.11.0/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:20772:18)
at async Object.runMain (/opt/actions-runner/_work/_tool/node/22.11.0/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:23091:19)
Worked around using this (requires jq)
- corepack enable
+ npm install -g $(jq -r '.packageManager' package.json)
Without jq:
- corepack enable
+ npm install -g $(sed -nE 's/.*"packageManager": "([^"]+)".*/\1/p' package.json)
Just putting it out there. For me the problem was the docker engine which was preinstalled with ubuntu 20.4.
I installed yarn globally, the path existed in ENV, I could succesfully execute yarn via cli but I would get the "yarn: command not found" error message whenever the self-hosted runned was executed.
Unistalling the docker engine fixed the issue for me. I do not no the reason for this.
FYI: There isn't a chicken-and-egg problem, you don't need Node to install yarn:
curl -fsSL -o ~/bin/yarn \ https://github.com/yarnpkg/yarn/releases/download/v1.22.17/yarn-1.22.17.js chmod +x ~/bin/yarn
I had to add to the path too:
- name: Install yarn
run: |
curl -fsSL -o ~/bin/yarn https://github.com/yarnpkg/yarn/releases/download/v1.22.17/yarn-1.22.17.js
chmod +x ~/bin/yarn
echo "$HOME/bin" >> $GITHUB_PATH
FYI: There isn't a chicken-and-egg problem, you don't need Node to install yarn:
curl -fsSL -o ~/bin/yarn \ https://github.com/yarnpkg/yarn/releases/download/v1.22.17/yarn-1.22.17.js chmod +x ~/bin/yarnI had to add to the path too:
- name: Install yarn run: | curl -fsSL -o ~/bin/yarn https://github.com/yarnpkg/yarn/releases/download/v1.22.17/yarn-1.22.17.js chmod +x ~/bin/yarn echo "$HOME/bin" >> $GITHUB_PATH
This still works, we just have to manually bump versions in the URL. Why is this not in the action itself?