npm package.json bin won't work on Windows

funerr picture funerr · Aug 15, 2014 · Viewed 16.7k times · Source

I am trying to start my cli tool via the package.json bin property.

I have the following:

...
"name": "mycli",
"bin": "./bin/mycli",
...

When I open the cmd in the package path and type: "mycli" it says that the command is not recognized.

Should I run an npm command? or use the scripts property? am I trying to access the bin property incorrectly?

Answer

Rodrigo Medeiros picture Rodrigo Medeiros · Aug 16, 2014

Try to specify the name of your cli tool in the bin property, like:

"bin": {
  "mycli": "./bin/mycli" // or "/bin/mycli.js" if it's a .js file
}

Then, run npm link, from inside your project folder, to create a global symbolic link to the current folder.

Don't forget to add the "preferGlobal": "true" property just before the bin property in your package.json file, in order to warn users to install your module globally.