[BUG] npm trust rejects "--otp 123456" and other space-separated global options: "Unknown positional argument"
メンテナーはふだん 2 日以内に返信
@igorsaevets がすでに取り組んでいます。
2026年11月22日 から。
評価
- 難易度
- 3/5
- 見積もり時間
- 半日
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- javascript, node.js
- 領域
- cli
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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)
- 主要言語
- JavaScript
- スター
- 10.3k
- フォーク
- 5k
- 平均マージ
- 4日 11時間
- マージ済み PR(30日)
- 26
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
npm/cli のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 2 日以内に返信
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endings対応中かも @saruk-vedant が 7 日前に担当しました。 オープンBug Needs Triage Triage Requested
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
-
[BUG] npm pkg delete removes the first array item for a nonexistent property対応中かも @drawliin が 42 日前に担当しました。 オープンcmd:delete Priority 3
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 2 日以内に返信
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings logged再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンEngineering Priority 1
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
メンテナーはふだん 2 日以内に返信
-
`npm audit signatures` does not report how many packages it skipped for want of registry keys対応中かも @greenlincoln05 が 63 日前に担当しました。 オープンPriority 3
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 2 日以内に返信
似ている issue
-
docs: add SECURITY.md vulnerability reporting policy対応中かも @AK-Lmn が今日担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
flisk-sh/linux2wasm#12 ·
メンテナーはふだん 1 日以内に返信
-
possible bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
Mintplex-Labs/anything-llm#7388 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 60/100
メンテナーはふだん 1 日以内に返信
-
v6: Minified bootstrap.min.css is missing header info対応中かも @lazerg が今日担当しました。 オープンbug build confirmed has-pr v6
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
githubnext/gh-aw-workshop#6332 ·
メンテナーはふだん 1 日以内に返信