-
Notifications
You must be signed in to change notification settings - Fork 240
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
[RRFC] Reintroduce global-only bin command #657
Comments
I like the idea of coming at this from solving a specific problem, i.e. "Telling windows users the extra directory they need to add to their path" This keeps us on task and hopefully steers us away from displaying local bin info. There has also been discussion about supplementing
|
@molisani if I'm working on a long-wished-for iteration of npm doctor that allows for discrete checks, and adding this as an "environment" check is on the list of things to do. |
Having this live in However, I was also looking through our code for any other dependencies on |
If you want to execute a globally installed script you can use npx. What's the use case where that is not available? |
Manually having folks fix their path to include the global bin dir feels like fixing a symptom not a problem. The problem being: why isn't this a part of their node installation? How do we fix THAT problem? As far as I can tell, either you want to invoke a globally installed bin and let the |
Isn’t this |
No that is the |
I haven't personally seen this in a while, possibly because we introduced the |
As for the programmatic use case I mentioned above, it had been a while since I looked into it (I searched everything we had for |
Motivation ("The Why")
With npm v9, the
npm bin
command was removed, which also removed thenpm bin -g
command. It displayed the path for globally-installed packages, and also checked to make sure that that path was included in the$PATH
environment variable. For unix/mac, this is generally not an issue as global packages are installed to the same location as the node/npm binaries.However, with Windows it's different as the global packages are installed in a completely separate directory from the node installation. Being able to run
node
does not necessarily mean that the user is also able to run the globally installed packages. Taken from the Windows installer, updating the$PATH
variable is split into two different "features".With a clean install of node on Windows with these two features selected, it will add two separate locations to the
$PATH
:This is because of the value of
prefix
decided by the builtin config, which is set to%APPDATA%\npm
by default:If I then install a package (ex:
typescript
) withnpm i -g typescript
, this installstsc
toC:\Users\<username>\AppData\Roaming\npm\tsc
which I'm only able to invoke successfully because of the second new entry in my PATH variable. This logic is entirely custom to npm, as it's derived from npm'sprefix
config value.This all works seamlessly in the ideal case, but speaking as someone that handles troubleshooting for a large population of developers that are not always primarily doing Node/npm/JS development, incomplete or inaccurate
$PATH
variables have been an uncommon yet consistent issue. It was useful for us to havenpm bin -g
as that could prompt the user to add the global package location to their$PATH
if it wasn't already set (as it would warn with(not in PATH env variable)
).Given the nature of Windows' two-location installation, this does seem like a Windows-only problem. As such, I'm not sure what the cleanest fix would be. For this use case we do not need any of the "non-global" functionality of
npm bin
without-g
that allowed for the aforementioned bad behavior, so I'm not suggesting that this command be added back as it was. If the functionality to check the global install location (and also if that was in the$PATH
variable) could be added to an existing command or even a new command, that would work well for us. I'd be happy to contribute such a feature (whatever it may look like) if that sounds like a good idea to all involved.Example
This RFC would be for a new command, subcommand, or flag that reproduces the behavior of
npm bin -g
. Specifically, printing the location of globally installed executable packages and checking whether that location is available in the$PATH
environment variable.Potential suggestions:
npm prefix -g
as this path is derived from theprefix
config value.$PATH
-related logicHow
Current Behaviour
No platform-independent way to calculate location of globally installed packages.
Desired Behaviour
References
npm bin
cli#5459The text was updated successfully, but these errors were encountered: