Skip to content

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

Open
@godlygeek

Description

@godlygeek

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or request to improve the current logic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions