volta-cli / volta

Volta: JS Toolchains as Code. ⚡
https://volta.sh
Other
10.81k stars 227 forks source link

Issue with developing Node CLI with Volta #1047

Open fnick851 opened 2 years ago

fnick851 commented 2 years ago

I have a simple CLI specified in package.json like this:

{
  "name": "cli",
  "version": "1.0.0",
  "bin": {
    "mycli": "./code.js"
  }
}

After I ran npm install -g in the root directory of the project (where package.json is), I can see something is installed globally:

❯ npm list -g --depth 0
/Users/Noah/.volta/tools/image/node/16.13.0/lib
├── cli@1.0.0 -> ./../../../../../../workspace/JavaScript/Node/fm-node-intro/cli
├── corepack@0.10.0
└── npm@8.1.0

But the executable is not recognized:

❯ cli
zsh: command not found: cli
❯ mycli              
zsh: command not found: mycli

I try to uninstall it globally:

❯ npm uninstall -g cli
   note: using Volta to uninstall cli
Volta warning:  No package 'cli' found to uninstall

❯ npm uninstall -g mycli 
   note: using Volta to uninstall mycli
Volta warning:  No package 'mycli' found to uninstall

It seems like it is using Volta under the hood and can't uninstall it. And it is not installed for Volta:

❯ volta list
⚡️ Currently active tools:

    Node: v16.13.0 (default)
    npm: v8.1.4 (default)
    Yarn: v1.22.17 (default)
    Tool binaries available:
        nest (default)
        vue (default)
        pnpm, pnpx (default)
        serverless, sls (default)
        vc, vercel (default)

See options for more detailed reports by running `volta list --help`.

My question is, with Node managed by Volta, how do I develop a Node CLI and install it globally to test it? It seems like there's some difference comparing to using the standard Node installed with Node installer, and I can't find it documented anywhere. Supposedly, after I ran npm install -g with that package.json, I should just be able to run mycli to execute the CLI.

sergeysedoy97 commented 2 years ago

Had the same problem. Just use npx npm i -g ., because you need to install it in bundled-npm. To run the app, just use npx my-cli. Also, you can use npm link.

Elevating7734 commented 1 year ago

Is there any movement on answering how to develop a Node CLI and install it globally? This is a blocker for our use case.