Packages

commander

15.1.0 · 7 Nov 2026MIT785.6M / weekRepositoryHomepagenpmAtom feed

Your version

8.0.0

major25 Jun 2021Where it was published

8.3.0 is the newest release of 8.x.

In short

5 breaking2 deprecated9 new5 changed1 internal

  • Breaking
    • Help method .visibleArguments() returns array of Argument

  • Breaking
    • Commander 8 requires Node.js 12 or higher

  • Breaking
    • CommanderError code commander.invalidOptionArgument renamed commander.invalidArgument

  • Breaking
    • TypeScript declaration for .addTextHelp() callback no longer allows result of undefined, now just string

  • Breaking
    • TypeScript declaration for default export of global Command object

  • Deprecated

    Second parameter of cmd.description(desc, argDescriptions) for adding argument descriptions

  • Deprecated

    InvalidOptionArgumentError (replaced by InvalidArgumentError)

Release note

Added

  • .argument(name, description) for adding command-arguments

    • supports default value for optional command-arguments

    • supports custom processing function

  • .createArgument() factory method

  • .addArgument()

  • Argument supports .choices()

  • .showHelpAfterError() to display full help or a custom message after an error

  • .hook() with support for 'preAction' and 'postAction' callbacks

  • Client typing of .opts() return type using TypeScript generics

  • The number of command-arguments is checked for programs without an action handler

  • .getOptionValue() and .setOptionValue()

Changed

  • Refactor and simplify TypeScript declarations (with no default export)

  • .parseAsync() is now declared as async

  • Breaking
    • Help method .visibleArguments() returns array of Argument

  • Breaking
    • Commander 8 requires Node.js 12 or higher

  • Breaking
    • CommanderError code commander.invalidOptionArgument renamed commander.invalidArgument

  • Breaking
    • TypeScript declaration for .addTextHelp() callback no longer allows result of undefined, now just string

  • Refactor index.tab into a file per class

  • Remove help suggestion from "unknown command" error message (see .showHelpAfteError())

  • Command property .arg initialised to empty array (was previously undefined)

Deprecated

  • Deprecated

    Second parameter of cmd.description(desc, argDescriptions) for adding argument descriptions

    • (use new .argument(name, description) instead)

  • Deprecated

    InvalidOptionArgumentError (replaced by InvalidArgumentError)

Removed

  • Breaking
    • TypeScript declaration for default export of global Command object

    • (still available as named program export)

Migration Tips

If you have a simple program without an action handler, you will now get an error if
there are missing command-arguments.

program
  .option('-d, --debug')
  .arguments('<file>');
program.parse();
$ node trivial.js 
error: missing required argument 'file'

If you want to show the help in this situation, you could check the arguments before parsing:

if (process.argv.length === 2)
  program.help();
program.parse();

Or, you might choose to show the help after any user error:

program.showHelpAfterError();

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.