nodejs/node · info · Error

${argv[2]} not recognized

Error message

${argv[2]} not recognized

What it means

Thrown by the npm `org` command's shell-completion (autocomplete) handler when the subcommand word at argv[2] does not match any of the recognized values: ls, add, rm, set. The completion function returns suggestion arrays for known subcommands and throws for anything else. This only fires during tab-completion, not during normal command execution.

Source

Thrown at deps/npm/lib/commands/org.js:30

    'ls orgname [<username>]',
  ]

  static params = ['registry', 'otp', 'json', 'parseable']

  static async completion (opts) {
    const argv = opts.conf.argv.remain
    if (argv.length === 2) {
      return ['set', 'rm', 'ls']
    }

    switch (argv[2]) {
      case 'ls':
      case 'add':
      case 'rm':
      case 'set':
        return []
      default:
        throw new Error(argv[2] + ' not recognized')
    }
  }

  async exec ([cmd, orgname, username, role]) {
    return otplease(this.npm, {
      ...this.npm.flatOptions,
    }, opts => {
      switch (cmd) {
        case 'add':
        case 'set':
          return this.set(orgname, username, role, opts)
        case 'rm':
          return this.rm(orgname, username, opts)
        case 'ls':
          return this.ls(orgname, username, opts)
        default:
          throw this.usageError()
      }

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Re-run `npm completion >> ~/.bashrc` (or ~/.zshrc) to regenerate the completion script for your installed npm version
  2. Verify the subcommand you are tab-completing is valid — only ls, add, rm, set are supported
  3. Update npm to the latest stable version: `npm install -g npm@latest`
  4. Restart your shell or `source ~/.bashrc` after regenerating completions

Example fix

// No code fix — this is a shell-completion path.
// User fix: regenerate completions
//   npm completion >> ~/.bashrc
//   source ~/.bashrc
Defensive patterns

Strategy: validation

Validate before calling

const VALID_ORG_SUBCOMMANDS = ['ls', 'add', 'rm', 'set']
function isValidOrgSubcommand(cmd) {
  return VALID_ORG_SUBCOMMANDS.includes(cmd)
}
// Before completion logic:
if (!isValidOrgSubcommand(argv[2])) {
  console.error(`Valid subcommands: ${VALID_ORG_SUBCOMMANDS.join(', ')}`)
  process.exit(1)
}

Type guard

function isOrgSubcommand(cmd) {
  return typeof cmd === 'string' && ['ls', 'add', 'rm', 'set'].includes(cmd)
}

Prevention

When it happens

Trigger: Triggered when the shell invokes npm's completion machinery and the word being completed at position argv[2] is not one of 'ls', 'add', 'rm', or 'set'. For example, pressing tab after `npm org dele<TAB>` would pass 'dele' (or similar non-matching fragment) into the switch default.

Common situations: Developers rarely hit this directly — it surfaces in shell completion scripts (bash/zsh) that wire into `npm completion`. A misconfigured completion script, a stale shell completion cache, or a typo while tab-completing can cause it. Upgrading npm and not re-running `npm completion > ~/.bashrc` can leave stale completions.

Related errors


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