volta icon indicating copy to clipboard operation
volta copied to clipboard

Issues with global install for local CLI tool

Open briantjacobs opened this issue 3 years ago • 5 comments

Volta looks great but not sure how to resolve an issues with a local project--I have a node CLI tool I install locally (not hosted in npm)--I clone a repo, cd into it, run npm install -g, it has the following in its package.json

  "bin": {
    "trudy": "./app/index.js"
  },

Historically npm install -g works fine and then I can run the trudy command anywhere. Using volta, it doesn't register the command and I'm not sure what i'm missing according to the volta documentation.

image

Volta working as expected for projects published to npm--you can see prettier in my tool binaries available, but no trudy command as i'm expecting

image

edit: on MacOS 10.14.6

briantjacobs avatar Feb 14 '22 17:02 briantjacobs

Within a local project looks like if i run npm link instead of npm install -g volta registers the local bin as expected, and appears to provide the same behavior. I'm unclear what the functional difference is between these 2 commands in a local project

The npm docs explicitly support local/global installs like this: See "in a package directory, no arguments" -> "in global mode" https://docs.npmjs.com/cli/v8/commands/npm-install

briantjacobs avatar Feb 14 '22 21:02 briantjacobs

Hi @briantjacobs, thanks for reporting! I think this is likely a miss in how we handle installs to register the binaries so that Volta can handle them. We correctly work with npm install -g <package>, but it appears we aren't setting things up correctly for an argument-free npm install -g.

As you noted, in the short term npm link can be a workaround, since I believe the behavior is approximately the same between the two.

charlespierce avatar Feb 15 '22 08:02 charlespierce

Thanks. npm link looks identical for my purposes, a fine workaround. Didn't have any luck finding an explanation on the difference between that and npm install -g (no args) however. I'm all ears if anyone happens to know

briantjacobs avatar Feb 16 '22 21:02 briantjacobs

Had the same problem. See my https://github.com/volta-cli/volta/issues/1047#issuecomment-1042856329.

sergeysedoy97 avatar Feb 17 '22 11:02 sergeysedoy97

I'm having the same problem, @charlespierce any updates on this issue?

In my case, npm link doesn't work, because it creates the binary only for the CLI folder, I can't run the cli in another directory.

When I try to run the cli in another directory, I receive this error message:

Volta error: Could not locate executable `my-cli` in your project.

Please ensure that all project dependencies are installed with `npm install` or `yarn install`

edit: if a run npm link my-cli in another directory, all works as expected, but I have to make the link every time I change directories.

emersonlaurentino avatar Oct 19 '23 02:10 emersonlaurentino