nodejs/node · warning · Error

${argv[2]} not recognized

Error message

${argv[2]} not recognized

What it means

During shell tab-completion for `npm install-scripts`, the static completion handler returns candidate subcommands for the first position and throws '<token> not recognized' for any token beyond that which is not in {approve, deny, ls, prune}. This is a completion-time guard, not raised by exec.

Source

Thrown at deps/npm/lib/commands/install-scripts.js:30

    'approve --all',
    'deny <pkg> [<pkg> ...]',
    'deny --all',
    'ls',
    'prune',
  ]

  static params = ['all', 'allow-scripts-pin', 'dry-run', 'json']

  static async completion (opts) {
    const argv = opts.conf.argv.remain
    const subcommands = ['approve', 'deny', 'ls', 'prune']
    if (argv.length === 2) {
      return subcommands
    }
    if (subcommands.includes(argv[2])) {
      return []
    }
    throw new Error(`${argv[2]} not recognized`)
  }

  async exec (args) {
    const [sub, ...rest] = args
    switch (sub) {
      case 'approve':
        return this.runMode('approve', rest)
      case 'deny':
        return this.runMode('deny', rest)
      case 'ls':
      case 'list':
        return this.runMode('list', rest)
      case 'prune':
        return this.runMode('prune', rest)
      default:
        throw this.usageError(
          sub ? `\`${sub}\` is not a recognized subcommand.` : undefined
        )

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Use a valid subcommand: approve, deny, ls (list), or prune
  2. Regenerate shell completion (`npm completion >> ~/.bashrc` / zsh equivalent) to refresh tokens
  3. If calling completion programmatically, constrain candidates to the documented set
Defensive patterns

Strategy: validation

Validate before calling

const subcommands = ['approve', 'deny', 'ls', 'prune']
if (!subcommands.includes(token)) { /* omit from completion candidates */ }

Type guard

function isInstallScriptsSubcommand(t) {
  return ['approve', 'deny', 'ls', 'prune'].includes(t)
}

Prevention

When it happens

Trigger: Triggering completion (npm install-scripts <TAB>) with a token outside the valid set, or a programmatic completer passing an invalid subcommand.

Common situations: Stale shell completion cached from before install-scripts existed or after its subcommand set changed; wrappers invoking completion with arbitrary tokens.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/7402ab8069d23570. Report an issue: GitHub.