setup-node: Error: Unable to locate executable file: yarn. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

I have

            uses: actions/setup-node@v3
              with:
                  node-version: 16
                  cache: 'yarn'

Maybe my expectation is incorrect, but I would expect this package to setup node and yarn on the machine.

Description: crashes with Error: Unable to locate executable file: yarn. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

Action version: 3

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version: node 16

Repro steps:

Expected behavior: yarn get’s installed as part of this step

Actual behavior: crashes with

Run actions/setup-node@v3
Found in cache @ /Users/runner/actions-runner/_work/_tool/node/16.15.0/arm64
Error: Unable to locate executable file: yarn. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Also running into this on self-hosted. Used to work fine on GitHub hosted runners.

A bit odd indeed that yarn is a precondition for setting up node here.

I just ran into this problem, and I’m curious why the setup-node action doesn’t you know, setup node? Doesn’t pre-installing tools on the self-hosted runner defeat the purpose?

IMO the action should just call corepack as part of the install. If the repo has packageManager set, everything will just work.

of course I don’t. I do not know why I was expecting this action to set it up. Sorry

why we’re not going to install some extra tools

@dmitry-shibanov I disagree, yarn / pnpm are not some random extra tools, they are pretty core to the NodeJS ecosystem and used pretty extensively. This setup-node action acknowledges this by giving support for caching dependencies installed with those tools. IMHO, it doesn’t make sense that I need to somehow, install yarn after using setup-node, loosing the ability to use the build in caching support and hacking it like @neseleznev showed.

Hello @capaj. Thank you for your report. Do you have yarn preinstalled on your self-hosted runner ?

Agree with @milesj here. Especially considering that corepack makes installing yarn so easy, seems like setup-node should take care of this implicitly when yarn is set as cache type, at least for newer node versions =)

of course I don’t. I do not know why I was expecting this action to set it up. Sorry !

I don’t think you’re dumb at all! 😅

@neseleznev totally agree with you, to me it sounds like yarn and pnpm are tools that should be controlled by setup-node, specially if this action supports cache for those, otherwise, it’s contradictory.

Hello @milesj. The hosted runners have preinstalled versions of software such as yarn node and etc. The main purpose of setup-node is to set up Nodejs on the machine that is why we’re not going to install some extra tools. Besides, that if the action had been installing tools by default it would require clean up machine from it. It looks like something out of scope of action.

tldr: add step to install yarn

- name: For act to work (local testing)
  run:  npm -g install yarn

thinks you

I hit this today when using act.

That’s not dumb at all. It’s quite opposite — I have to preinstall yarn globally (Node.js npm package) to the runner before installing Node.js 🤯

I feel frustrated. For those who’s with me, try the approach to cache the whole node_modules as described in https://oozou.com/blog/ci-cd-tips-improve-your-ci-cd-with-cache-github-version-209

Thus, my final action looks like

jobs:
  build-ui:
    runs-on: self-hosted
    timeout-minutes: ${{ fromJSON(inputs.timeout-minutes) }}
    steps:
    - uses: actions/checkout@v3

    - uses: actions/setup-node@v3
      with:
        node-version: 16.14

    - name: Get node version
      id: node
      run: |
        echo "::set-output name=version::$(node -v)"

    - name: Get node_modules cache
      uses: actions/cache@v3.0.2
      id: node_modules
      with:
        path: |
          **/node_modules
        # Add node version as a cache key to avoid yarn recompilation for particular node as it doesn't change often
        key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}-${{ steps.node.outputs.version }}

    - name: Build
      env:
        CHROME_BIN: /usr/bin/google-chrome
      run: |
        npm i --g yarn #TODO:5520 the version is not fixed, shall we?
        yarn install --frozen-lockfile # optional, --immutable
        npm run prod:${{ inputs.project }}
      shell: bash
      working-directory: ...

I’ve seen an action to run yarn without installing it on the runner

e.g.

https://github.com/marketplace/actions/github-action-for-yarn