actions / actions/setup-node

nodeenv falls back to /usr/bin/nodejs instead of the node installed by actions/setup-node

Open
#905 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
TypeScript
Stars
5k
Forks
1.7k
Avg merge
3d 12h
Merged PRs (30d)
2

Description

Description:
In a runs-on: ubuntu-latest GitHub hosted runner, I found that even after doing:

      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: 16

that pre-commit run -a was failing to run a pre-commit hook configured as:

  - repo: https://github.com/pre-commit/mirrors-prettier
    rev: v3.1.0
    hooks:
      - id: prettier
        args: [--no-editorconfig]
        exclude: "^asv\\.conf\\.json$"
        exclude_types: [html]

with an error saying:

prettier requires at least version 14 of Node, please upgrade

Which was surprising, seeing as how we had just installed node version 16.

It turns out that pre-commit runs nodeenv, and nodeenv looks first for a binary named nodejs, and then falls back to looking for one named node:

https://github.com/ekalinin/nodeenv/blob/eaa9de97e561ab4f99458c94633e92547e72d5f1/nodeenv.py#L931-L938

And it seems like actions/setup-node is only installing one named node, and not one named nodejs, so nodeenv found /usr/bin/nodejs first and preferred that over /opt/hostedtoolcache/node/16.20.2/x64/bin/node.

Should the hostedtoolcache contain a nodejs as well? Or perhaps nodeenv should prefer node over nodejs?

Action version:
actions/setup-node@v4

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:

Repro steps:
See https://github.com/bloomberg/memray/actions/runs/6984525297/job/19007471664 for a failed run where /usr/bin/nodejs was chosen instead of /opt/hostedtoolcache/node/16.20.2/x64/bin/node

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the actions/setup-node@v4 workflow and the nodeenv.py lookup around lines 931-938, then reproduce the failing pre-commit run from the linked GitHub Actions job. Trace which executable is selected on Ubuntu hosted runners; the issue is done when the configured Node 16 installation is selected and the Prettier hook succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, node.js, typescript
Domain
ci-cd, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.