commander.js: (1) does not exist, try --help
After calling
program.parse(process.argv);
I get
index-server(1) does not exist, try --help
Commands Run
$ node ../../lib/cmd/index.js server
Relevant Code
// index.js
const { root } = require('./root');
root.parse(process.argv);
//root.js
import * as root from "commander";
root
.version(version, "-v, --version")
.description("description")
.option("-s, --select <id>", "select")
.option("-e, --env <env>", "Environment to use for commands.")
export { root }
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 16
- Comments: 15
Here is the workaround I am using for my project:
package.json:
For windows the value ./my-script-<command-name> is used to try and find the executable file. For unix the key “my-script-<command-name>” is used to try and find the executable file.
If the key and value in package json bin is the same it works fine on both unix and windows. We wont get the not found error (which occurs if package.json 's package.bin is “my-script” : “./index.js”).
my-script.js
Folder structure:
I have same issue on Mac! Windows works.
I was not able to reproduce with your code fragment, but it looks like you have (accidentally) invoked the Git-style sub-commands processing which searches for separate executables.
Do you have code like
root.command("server", description)in your failing program?any update on this? ive tried @fabioricali and @knyy’s workarounds with no success.
i cannot reproduce the issue locally using
yarn linkornpm linkbut after publishing to npm and installing with yarn, the issue appears.also, if i remove the globally installed yarn package and install with npm instead of yarn it works
Thanks for the work-arounds @david-mohr
There is a change being prepared for release in Commander v2.20.0 which should help with the Yarn issue in particular: #935
@shadowspawn did it make the 2.20.0 release - I fear not?
currently running 2.20.0 on MacOS it seems that even if one uses the
.actionsyntax, the code still requires thegitstyle js file per command?As a side question, is is possible to have global options, and commands, such that the global option provide the ability to override the commands behavior.