Reputation: 751
I've been developing a later-to-be-release Open Source project with Node as a CLI tool. The CLI itself works great I only need to test if it works while on another project, so for that I installed the projects globally npm install -g
without errors, but for the life of me I can't use the CLI.
I get the following error:
The odd thing is that the directory and file does exist in the global npm folder:
This is the project's package.json
:
Am I not understanding how making a npm/node CLI works? What I'm missing?
EDIT 1:
This is my index.js file:
And this is the commander.js file:
EDIT 2:
After creating a test project as @AngYC suggested I could use the test cli successfully, while inspecting the difference I found this. Inside C:\Users\Ivan\AppData\Roaming\npm
the .cmd of both projects are quite different:
EDIT 3 (Solution):
After fiddling around I found out that the file that really needed the shebang (#!/usr/bin/env node
) was only index.js
file and not the commander.js
one. Removing the shebang in that file solved the problem
Upvotes: 2
Views: 544
Reputation: 9933
Try to uninstall cli
run npm rm -g cli
or sudo npm rm -g cli
. Then you run: npm install cli -g
If the problem persist, you might want to remove you npm package globally, probably there might be some conflicting things running.
Type this: %appdata%
(either in explorer, run prompt, or start menu).
You can simply remove all globally installed npm packages by deleting the contents of:
C:\Users\username\AppData\Roaming\npm
Then you might also want to clear all the your cache run npm cache clear
or npm cache clear --force
as the case might be.
Then you reinstall all your packages that were install globally again.
If problem still persist, check this:
When you run npm root -g
, it yields C:\Users\<username>\AppData\Roaming\npm\node_modules
, or even, you should check your path maybe the executable binaries and .cmd
files end up in C:\Users\<username>\AppData\Roaming\npm
instead of C:\Users\<username>\AppData\Roaming\npm\node_modules
, you will need to add that path to the PATH env. variable.
I hope this resolves your issue.
Upvotes: 0
Reputation: 6313
You may want to try to link
your local package to your global executable list.
https://docs.npmjs.com/cli/link
All you have to do is run npm link
in the folder you got your tool and it should make the command available globally.
Upvotes: 1