[BUG] npm trust rejects "--otp 123456" and other space-separated global options: "Unknown positional argument"

Abierto
#10,334 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@igorsaevets ya está trabajando en esto.

Desde el 22/11/2026.

  • #10335 de @igorsaevets — abierto
  • #10363 de @ayam04 — abierto
  • #10366 de @MFA-G — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
Medio día
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
javascript, node.js
Área
cli

Línea de trabajo

Start in lib/base-cmd.js: flags() re-parses config.argv with nopt using only the subcommand's static definitions, and the positional check later rejects leftover values in remains. Compare with the static definitions in lib/commands/trust/github.js (only dry-run, json, registry, yes are listed) and with lib/npm.js, where commands without static definitions skip flags() entirely. Done means npm trust github ... --otp 123456, --userconfig <file>, --cache <dir> and --loglevel warn all parse, with --file/--repo still working. Note an open PR (#10335) already targets this, so check it before starting.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Bug Needs Triage Triage Requested
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 trust subcommands reject the value of a global option when it follows the option after a space. --otp 123456, --userconfig <file>, --cache <dir> and --loglevel warn all stop with EUSAGE. The same options written with = pass, and so does --registry <url>, which the subcommand lists in its own definitions.

$ npm trust github demo-pkg --file publish.yml --repo example/demo --allow-publish --dry-run --otp 123456
npm error code EUSAGE
npm error
npm error Unknown positional argument: 123456
npm error
npm error Create a trusted relationship between a package and GitHub Actions

--otp matters for this command: npm trust sends its requests through otplease, which reads it.

npm 12.2.3, the command above with one option added (--dry-run, so nothing is sent):

Added option Result
(none) passes the argument check
--otp 123456 Unknown positional argument: 123456
--otp=123456 passes
--userconfig <file> Unknown positional argument: <file>
--userconfig=<file> passes
--cache <dir> Unknown positional argument: <dir>
--loglevel warn Unknown positional argument: warn
--registry https://registry.npmjs.org/ passes

npm trust list demo-pkg --otp 123456 fails the same way; with --otp=123456 it goes on to the registry. npm 11.21.3 and 11.19.0 give the same results.

Other projects have run into this and switched to --otp=<code> or npm_config_otp: remix-run/remix#12195 (npm 12), dxos/dxos#14062 (npm 11.15.0), rigsmith/rigsmith#439, and mark1russell7/template#6, which hit it with --fetch-retries too.

Expected Behavior

The value belongs to the option, as it does with --otp=123456: npm trust accepts global options in both forms.

Steps To Reproduce
  1. No login is needed; --dry-run sends no request.
  2. npm trust github demo-pkg --file publish.yml --repo example/demo --allow-publish --dry-run --otp 123456
  3. See npm error Unknown positional argument: 123456.
  4. npm trust github demo-pkg --file publish.yml --repo example/demo --allow-publish --dry-run --otp=123456 passes the check and prints Establishing trust between demo-pkg package and GitHub Actions.
Cause

BaseCommand.flags() parses config.argv again with nopt, using only the subcommand's static definitions (lib/base-cmd.js#L314-L330). An option missing from that list is read as a boolean, its value stays in remains, and the positional check rejects it (lib/base-cmd.js#L444-L450). trust github lists dry-run, json, registry and yes from the global definitions (github.js#L44-L48), but not otp, userconfig, cache or loglevel. The other npm trust subcommands also set static definitions, so they go through the same check; commands without static definitions do not call flags() (lib/npm.js#L297-L313).

The open PR #9295 is about global options placed before the command name. With its change applied to npm 12.2.3, npm --otp=123456 trust github … passes, but every failing row above still fails.

Giving nopt in flags() the types of the global definitions that the command does not define fixes it in my test: on npm 12.2.3 with that change every row above passes, and --file and --repo are still parsed. flags() already keeps only the command's own keys in its result (lib/base-cmd.js#L357-L364), so global values still come from the first parse. Together with the #9295 change, the before-the-command case passes as well. I can open a PR with tests if that helps.

Environment
  • npm: 12.2.3 (also 11.21.3 and 11.19.0)
  • Node.js: 24.21.0
  • OS Name: Windows 11 (10.0.26200)
  • System Model Name: n/a
  • npm config: defaults, with userconfig pointing to an empty file (not logged in)
Lenguaje dominante
JavaScript
Estrellas
10.3k
Forks
5k
Merge medio
4 d 11 h
PR fusionados (30 d)
26

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de npm/cli

Todos los issues de npm/cli

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.