Skip to content

fix: keep npx command flags after negated switches like --no - #10155

Open
mkantautas wants to merge 1 commit into
npm:latestfrom
mkantautas:fix/npx-negated-switch
Open

mkantautas wants to merge 1 commit into
npm:latestfrom
mkantautas:fix/npx-negated-switch

Conversation

@mkantautas

Copy link
Copy Markdown

npx --no <command> <args> hands the command's own flags to npm. --no expands to --no-yes, and bin/npx-cli.js only knows the non-negated switch names, so it reads the command name as the value of --no-yes and never puts -- in front of the command. The same happens after --no-color, --local (--no-global) and other negated switches.

With npm 12.2.1 and a locally installed hello bin:

  • npx --no hello --edit x fails with EUNKNOWNCONFIG
  • npx --no hello --version prints npm's version
  • npx --no hello -c x fails with EUSAGE
  • npx --local hello --json runs hello without --json

npm 11 dropped these flags silently, for example --edit x was read as npm's --editor x.

A negated switch now takes the next argument only when nopt reads it as that switch's value, so --no=true, --no-color always and --no-workspaces null work as before. Plain switches are unchanged.

Testing

New cases in test/bin/npx-cli.js: bare negations put -- before the command (these fail without the change), and values that nopt reads after a negation stay before --. Also checked end to end against a local registry fixture. The full test suite passes on Linux with Node 22.22.2, 24.15.0 and 26.8.2.

References

Related to #8021

npx treated --no (expanded to --no-yes) and other negated switches such as --no-color as options that take a value, so the command name was consumed as that value and the command's own flags were parsed by npm. A negated switch now takes the next argument only when npm's parser reads it as the switch's value.
@mkantautas
mkantautas requested a review from a team as a code owner October 22, 2026 15:57
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.

1 participant