Commander.js: Error: command does not exist

Created on 22 Jan 2020  Â·  4Comments  Â·  Source: tj/commander.js

const program = require("commander");

program.version("0.0.1");
program.description("Webotron deploys websites to AWS");

program
  .command("list-buckets", "List all S3 buckets")
  .action(function() {
    console.log("list-buckets");
  })
  .parse(process.argv);

why this code snippet throws that error, this is the output when running the command:

››› node 01-webotron/webotron.js list-buckets                                                                                      
list-buckets
error: webotron-list-buckets(1) does not exist, try --help

OS: macOS
nodeJS version: v13.6.0
commander: "^4.1.0"

am I doing something wrong?

Most helpful comment

For historical reasons, .command() for an action handler has the description separately. When the description is included Commander assumes you have an executable subcommand. You want:

program
  .command("list-buckets")
  .description("List all S3 buckets")

See https://github.com/tj/commander.js#commands for examples

All 4 comments

For historical reasons, .command() for an action handler has the description separately. When the description is included Commander assumes you have an executable subcommand. You want:

program
  .command("list-buckets")
  .description("List all S3 buckets")

See https://github.com/tj/commander.js#commands for examples

Thank you for your quick response, I don’t know that, I’ll try it out :)

On a related note, I have changed the "error" to a "throw" in #1165 with some additional tips to hopefully make it quicker for the author to recognise and resolve the problem. (This change is not in a published prerelease yet.)

Commander v5.0.0 has been released with additional error output to make it easier to recognise and correct this issue.

https://github.com/tj/commander.js/releases/tag/v5.0.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shadowspawn picture shadowspawn  Â·  3Comments

youurayy picture youurayy  Â·  5Comments

oknoorap picture oknoorap  Â·  4Comments

cmoulliard picture cmoulliard  Â·  4Comments

san-templates picture san-templates  Â·  5Comments