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 4 years ago
  • Comments: 19 (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?

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

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

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.

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

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.

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! 😅

I’d suggest using corepack in a separate step while it’s not included as part of this action (it probably should be).

Corepack is included as opt-in since Node.js 14.19 / 16.9

The solution is simple, portable and reliable. It’ll automatically use the correct version for both Node and Yarn across all platforms.

package.json

  "volta": {
    "node": "20.11.1",
    "yarn": "4.1.1"
  },
  "packageManager": "yarn@4.1.1"

Note: Volta compliments well but is not required. If you use it, the package manager version should be in sync with the packageManager value.

Workflow

      - name: Install package manager (from package.json)
        run: |
          corepack enable
          corepack install

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version-file: package.json
          cache: 'yarn'

      - name: Install deps
        run: yarn install --frozen-lockfile --immutable

Note: using both --frozen-lockfile and --immutable will make sure it works for both older and newer version of Yarn, making it more portable across repos with different yarn versions.

Why not npm install --global yarn?

Re: @markanthonyuy and @onxb

tldr: add step to install yarn

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

Actually yarn recommends against this approach, in favour of Corepack. Source: https://yarnpkg.com/corepack

I hit this today when using act.

@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.

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 =)

tldr: add step to install yarn

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

upon trying last response, I am getting following error 😃 corepack: command not found

 - name: Conditionally Install Yarn for local Github Actions Emulator ACT
      if: ${{env.ACT}}
      run: npm -g install yarn

thinks you

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