Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git style commands and different than module name bin command issue #714

Closed
jarrodek opened this issue Nov 13, 2017 · 8 comments
Closed

Comments

@jarrodek
Copy link

jarrodek commented Nov 13, 2017

I have the following setup:

NPM module name: api-console-cli
Registered in package.json command: api-console

  "bin": {
    "api-console": "bin/api-console-cli.js"
  }

and the following error when trying to run the program on Windows:

C:\workspace\api-console-cli>api-console dev --help
module.js:491
    throw err;
    ^

Error: Cannot find module 'C:\workspace\api-console-cli\api-console-cli-dev'
    at Function.Module._resolveFilename (module.js:489:15)
    at Function.Module._load (module.js:439:25)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:578:3

Under Linux and Mac it works when the sub-command file is located in ./bin/api-console-dev.js. Windows throws an error which can be fixed by creating the ./bin/api-console-cli-dev.js. This file contains a require of the original file.

Apparently on windows commander ignores that the actual CLI command is different than the npm module name. It should request one file only on all platforms.

You can find the source code here: https://github.com/mulesoft-labs/api-console-cli

@patrickmcelwee
Copy link

patrickmcelwee commented Jul 3, 2018

I ran into this on Windows 7 as well, but my package.json looks like this:

  "main": "index.js",
  "bin": {
    "muir": "./index.js"
  }

and the error when running muir new, for example, is looking for a file named index-new. If I run muir demo, it looks for index-demo

@shadowspawn

This comment has been minimized.

@shadowspawn

This comment has been minimized.

@shadowspawn
Copy link
Collaborator

.command now supports the executableFile option (thanks to @abetomo).
Shipped in v3: https://github.com/tj/commander.js/releases/tag/v3.0.0

@shadowspawn
Copy link
Collaborator

shadowspawn commented May 23, 2020

The cause is Commander is using the script from the command line (i.e. process.argv[1]) to find the base name for the subcommand. This leads to a range of behaviours.

On Mac process.argv[1] when using:

  • node bin/api-console-cli.js has full path of local bin/api-console-cli.js
  • api-console has full path of installed command symlink api-console

On Windows my-cli is a cmd launch script and not a symlink so process.argv[1] when using:

  • node bin/api-console-cli.js has full path of local bin/api-console-cli.js
  • api-console has full path of installed bin/api-console-cli.js

A slightly fragile but backwards compatible behaviour might be to look for both variations on Mac, so that bin/api-console-cli-dev.js would be found whether launched directly using node or through the command, on Mac and Windows.

@shadowspawn
Copy link
Collaborator

Previous issue and associated PR: #826 #830

Issue covering multiple causes but some related comments: #786

@shadowspawn
Copy link
Collaborator

PR to resolve this issue: #1571

@shadowspawn shadowspawn added this to the Commander v9.0.0 milestone Sep 6, 2021
@shadowspawn shadowspawn removed their assignment Dec 25, 2021
@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Jan 29, 2022
@shadowspawn
Copy link
Collaborator

Commander v9 has been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants