Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

yarn fails in GitHub Actions: the engine node is incompatible with this module

ErrorThe engine "node" is incompatible with this module

Short answer

The Node version on the runner is older or newer than the engines range of a dependency. The Borales yarn action expects you to set up Node yourself first. Add actions/setup-node with an explicit node-version before the yarn step, or point it at a version file in the repo.

  • Applies to actions/setup-node v4, Yarn 1.x, GitHub Actions
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the Node version the job really uses and the range the failing package asks for.

    node --version
    node -p "require('./package.json').engines"
  2. 2Match what you see, then jump to its fix

    1. 1node --version in the job shows whatever Node is on the runner, not your project'sNo Node version is set before the yarn stepFix
    2. 2Your repo has .nvmrc or .node-version, but the workflow names another versionThe version differs from the one the project is built withFix
    3. 3The project is on Yarn 2 or later (a .yarnrc.yml file in the repo)The action is used with a newer Yarn than it supportsFix

What does the error look like?

  • The engine "node" is incompatible with this module

Cause 1 of 3

No Node version is set before the yarn step

1Check

setup-node uses the Node found on PATH when node-version is not given, and Borales' README says to run setup-node before the action to select the version.

grep -n -B2 -A4 "setup-node" .github/workflows/*.yml

2Fix

Add setup-node first, with an explicit version, then run the yarn step.

- uses: actions/setup-node@v4
  with:
    node-version: '22'
- uses: borales/actions-yarn@<release tag from its README>
  with:
    cmd: install

3Verify

The step prints the chosen Node version and yarn install passes.

node --version

Confirmed by github.com

Did this fix it?

Cause 2 of 3

The version differs from the one the project is built with

1Check

setup-node can read the version from a file, but if node-version is also set, node-version wins.

cat .nvmrc 2>/dev/null
grep -n "node-version" .github/workflows/*.yml

2Fix

Keep one source of truth: read the version from the file and drop the hard-coded value.

- uses: actions/setup-node@v4
  with:
    node-version-file: '.nvmrc'

3Verify

The job's node --version equals the file.

node --version && cat .nvmrc

Confirmed by github.com

Did this fix it?

Cause 3 of 3

The action is used with a newer Yarn than it supports

1Check

The action's README says it is compatible with Yarn 1.x only.

yarn --version

2Fix

For Yarn 2 and later, call yarn from a run step after setup-node instead of using this action.

- uses: actions/setup-node@v4
  with:
    node-version: '22'
- run: yarn install

3Verify

The install step runs with your Node version.

yarn --version

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Always give setup-node an explicit version; never rely on what the runner image has.
  • Keep engines in package.json and the CI version in one file.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.