Visitar URL original
fix: retry npm cache lookup with --force on EBADDEVENGINES by eran132 · Pull Request #1663 · actions/setup-node · GitHub
Skip to content

fix: retry npm cache lookup with --force on EBADDEVENGINES - #1663

Open
eran132 wants to merge 1 commit into
actions:mainfrom
eran132:fix/npm-cache-devengines
Open

eran132 wants to merge 1 commit into
actions:mainfrom
eran132:fix/npm-cache-devengines

Conversation

@eran132

@eran132 eran132 commented Nov 6, 2026

Copy link
Copy Markdown

Description:

With npm caching enabled, setup-node looks up the cache folder with npm config get cache in the workspace root. npm checks devEngines.packageManager from that package.json even for this read-only command, and exits with EBADDEVENGINES when the installed npm doesn't match. setup-node then fails before the workflow can install the package manager the project asks for.

This affects the three cases reported in #1553:

  • a project that requires a newer npm than the one bundled with Node (^11.10.0 on Node 22, >=12.2.2 on any current Node);
  • a monorepo with pnpm declared at the root and an npm project in a subfolder. This one fails on npm 11 as well, because npm still rejects a package-manager name mismatch.

The change keeps the current lookup as is. Only when it fails with EBADDEVENGINES does setup-node log a short note and retry once with npm config get cache --force. --force turns the devEngines check into a warning and still honours a project .npmrc cache= setting. Any other error, or a failing retry, is reported as before.

I didn't add --force unconditionally because npm then prints npm warn using --force Recommended protections disabled. for every project. I checked that on Node 18, 20, 22, 24 and 26, so every npm-cached job would show it.

Testing

  • Unit tests: 4 new cases in __tests__/cache-utils.test.ts (normal path doesn't use --force, EBADDEVENGINES triggers one retry, other errors don't retry, a failing retry surfaces its error). The full suite ran 10 times in node:24: 261/261 passed each time. format-check, lint and build are clean, and dist/ was rebuilt.
  • End to end on hosted ubuntu-24.04: eran132/setup-node-devengines-repro, run. 4 scenarios × Node 22/24/26 × 10 attempts, comparing upstream v7.1.0 with this branch. Jobs using this branch have no continue-on-error, so the post-job cache save passes as well:
Scenario v7.1.0 this PR
devEngines npm ^11.10.0 fails 10/10 on Node 22, passes on 24/26 passes 30/30 (retry only on Node 22)
monorepo: pnpm at the root, npm in app/ fails 30/30 passes 30/30
devEngines npm >=12.2.2 fails 30/30 passes 30/30
no devEngines (control) passes 30/30 passes 30/30, no retry and no --force warning

Related issue:
Fixes #1553

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

🤖 Generated with Claude Code

npm checks devEngines.packageManager from the workspace package.json
even for `npm config get cache`, so setup-node fails before the
workflow can install the required package manager (monorepos with
pnpm at the root, or projects that require a newer npm than the one
bundled with Node). Retry the lookup once with --force only when npm
reports EBADDEVENGINES; the normal path is unchanged.

Fixes actions#1553

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eran132
eran132 requested a review from a team as a code owner November 6, 2026 18:23
Copilot AI balanced review requested due to automatic review settings November 6, 2026 18:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the npm cache lookup retry change.

No open issues 🎉

What changed in this PR

This PR addresses #1553 by allowing setup-node’s npm cache lookup to recover from EBADDEVENGINES, so workflows can proceed before installing the required package manager.

Changes:

  • Retry npm config get cache once with --force only after an EBADDEVENGINES failure, preserving other error handling.
  • Add four unit tests covering normal lookup, retry success, unrelated errors, and retry failure.
  • Update both bundled action entrypoints with the retry logic.
File Description
src/​cache-utils.ts Adds the conditional npm cache lookup retry and informational log.
dist/​setup/​index.js Includes the retry logic in the setup bundle.
dist/​cache-save/​index.js Includes the retry logic in the cache-save bundle.
__tests__/​cache-utils.test.ts Tests successful lookups and retry/error behavior.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

npm config get cache fails with EBADDEVENGINES when requiring newer npm versions in devEngines

2 participants