setup-node: 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.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 143
- Comments: 17
Commits related to this issue
- Install yarn See https://github.com/actions/setup-node/issues/182 — committed to BlakeRain/blakerain.com by BlakeRain 3 years ago
- switching from yarn for more check this https://github.com/actions/setup-node/issues/182 — committed to ps173/noper by ps173 3 years ago
- switching from yarn for more check this https://github.com/actions/setup-node/issues/182 — committed to ps173/noper by ps173 3 years ago
- docs: add ruohola as a contributor (#182) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@use... — committed to deining/setup-node by allcontributors[bot] 3 years ago
- CI: have workflow install Yarn if not present This is useful e.g. for act [1] if using the medium-sized image. Taken from user @francis-switcho’s comment on actions/setup-node. [2] [1]: https://git... — committed to claui/vscode-ifm by claui 9 months ago
Workaround is to install yarn yourself using npm (after running this action)
and later can uninstall it -
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 yarnPublish 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 vianpm install -g yarn
and uninstall it at the end of your job withnpm uninstall -g yarn
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.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:
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:
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.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)
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.
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:
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):
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 forsetup-node
to pick it up.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
copy the path (not including the yarn)
Edit path
run
you got something like
aaaaa:bbbb:cccc
separated with
:
then paste the
/home/admin/.nvm/versions/node/v16.14.0/bin
so the
.path
becomeaaaaa: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 itRestart runner
You need restart it. so it will load the new path
Mostly you are running with
svc.sh
then stop itRun it again
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
@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
Let me get this straight, the solution is for the consumers to:
$GITHUB_PATH
actions/setup-node
$ yarn
That’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.
I have the error
yarn: command not found
(just forked your repo on V3)What is the best way to fix it ?
Log in github:
@pperzyna thanks! I spent 30mins guessing why it was not working even after updating the path. Seems
run.sh
has to be restarted.