[BUG] npm trust rejects "--otp 123456" and other space-separated global options: "Unknown positional argument"
Los mantenedores suelen responder en 2 días
@igorsaevets ya está trabajando en esto.
Desde el 22/11/2026.
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
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
- No login is needed;
--dry-runsends no request. npm trust github demo-pkg --file publish.yml --repo example/demo --allow-publish --dry-run --otp 123456- See
npm error Unknown positional argument: 123456. npm trust github demo-pkg --file publish.yml --repo example/demo --allow-publish --dry-run --otp=123456passes the check and printsEstablishing 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
userconfigpointing 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
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de npm/cli
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 2 días
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endingsPosiblemente ocupada @saruk-vedant la tomó hace 7 días. AbiertoBug Needs Triage Triage Requested
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
npm/cli#10316 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
[BUG] npm pkg delete removes the first array item for a nonexistent propertyPosiblemente ocupada @drawliin la tomó hace 42 días. Abiertocmd:delete Priority 3
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 2 días
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. AbiertoEngineering Priority 1
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
Los mantenedores suelen responder en 2 días
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysPosiblemente ocupada @greenlincoln05 la tomó hace 63 días. AbiertoPriority 3
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
npm/cli#10018 · 2 comentarios ·
Los mantenedores suelen responder en 2 días
Issues similares
-
docs: add SECURITY.md vulnerability reporting policyPosiblemente ocupada @AK-Lmn la tomó hoy. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 72/100
flisk-sh/linux2wasm#12 ·
Los mantenedores suelen responder en 1 día
-
possible bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Mintplex-Labs/anything-llm#7388 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 60/100
Los mantenedores suelen responder en 1 día
-
v6: Minified bootstrap.min.css is missing header infoPosiblemente ocupada @lazerg la tomó hoy. Abiertobug build confirmed has-pr v6
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
githubnext/gh-aw-workshop#6332 ·
Los mantenedores suelen responder en 1 día