[BUG] Every command checks devEngines, so npx fails in a project that pins another package manager

Aperta
#10,301 1 commento 2 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@ahmedisam99 ci sta già lavorando.

Dal 15/11/2026.

  • #10302 di @ahmedisam99 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, node.js
Ambito
cli

Direzione di ricerca

Start with the reproduction in the issue: a throwaway project whose package.json pins devEngines.packageManager to pnpm, then run npx -y cowsay hi and npm config get registry to see EBADDEVENGINES. The gate is in lib/npm.js and tests commandInstance.checkDevEngines, the instance method every BaseCommand has; the intended opt-in is the static checkDevEngines flag that BaseCommand sets to false and only ArboristCmd and run set to true. Done looks like npx, npm exec, npm config and npm view running normally while install, ci and run still check, matching the wording in docs/lib/content/configuring-npm/package-json.md. Note a fix with tests is already proposed in #10302, so coordinate before starting.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug cmd:install Priority 3
Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
This is not just a request to bump a dependency for a CVE
  • This is not solely a request to bump a dependency for a CVE
Current Behavior

npm checks devEngines before every command run inside a project.
In a project whose devEngines.packageManager names another package manager, npx, npm exec, npm config get and npm view all exit with EBADDEVENGINES, though none of them act on the project.

The gate in lib/npm.js reads the wrong property:

if (commandInstance.checkDevEngines && !this.global) {
  await commandInstance.checkDevEngines()
}

commandInstance.checkDevEngines is the method BaseCommand defines, so every command has it and the condition is always true.
The opt-in is the static checkDevEngines flag.
BaseCommand sets it to false, only ArboristCmd and run set it to true, and nothing reads it.
The gate has read the instance since #7766 added it, and that PR describes the check as being for "specific npm commands install, and run".

We hit this through MCP servers.
Claude Code starts stdio MCP servers with npx from the project folder, so once our repo pinned pnpm in devEngines, every npx-launched server failed to start there.

Expected Behavior

Only commands that opt in through the static flag check devEngines.
That is the ArboristCmd commands (install, ci, update, ls and the rest) and run, which test, start, stop and restart go through.
The package.json docs say the check "will run before install, ci, and run commands".
npx, npm exec, npm config and npm view should run.

I have a fix with tests and will open a PR.

Steps To Reproduce
mkdir devengines-repro && cd devengines-repro
echo '{ "devEngines": { "packageManager": { "name": "pnpm" } } }' > package.json
npx -y cowsay hi
npm config get registry

Both commands exit 1 with:

npm error code EBADDEVENGINES
npm error EBADDEVENGINES The developer of this package has specified the following through devEngines
npm error EBADDEVENGINES Invalid devEngines.packageManager
npm error EBADDEVENGINES Invalid name "pnpm" does not match "npm" for "packageManager"
npm error EBADDEVENGINES {
npm error EBADDEVENGINES   current: { name: 'npm', version: '12.2.2' },
npm error EBADDEVENGINES   required: { name: 'pnpm' }
npm error EBADDEVENGINES }

Setting npm_config_force=true turns the error into a warning, and npx --prefix <a folder without devEngines> avoids it.

Environment
  • npm: 12.2.2, also 11.20.0
  • Node.js: 26.13.1
  • OS Name: Arch Linux
  • System Model Name: n/a
  • npm config:
; defaults, the repro sets nothing
Lingua principale
JavaScript
Stelle
10.3k
Fork
5k
Merge medio
4g 11h
PR unite (30g)
26

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di npm/cli

Tutte le issue di npm/cli

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.