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

オープン
#10,334 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@igorsaevets がすでに取り組んでいます。

2026年11月22日 から。

  • #10335 @igorsaevets による — オープン
  • #10363 @ayam04 による — オープン
  • #10366 @MFA-G による — オープン

評価

難易度
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 の本文から書いたものです。

説明

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)
主要言語
JavaScript
スター
10.3k
フォーク
5k
平均マージ
4日 11時間
マージ済み PR(30日)
26

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

npm/cli のほかの issue

npm/cli の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。