0

I'm trying to globally install a package that has to be installed from an administrative cmd/powershell (it uses windows-build-tools). When I install it using an administrative powershell, everything works fine - the install runs with no errors, and the command line interface of the package is added to the path:

PS C:\WINDOWS\system32> npm install -g prisma
C:\Users\XXX\AppData\Roaming\npm\prisma -> C:\Users\XXX\AppData\Roaming\npm\node_modules\prisma\dist\index.js
+ prisma@1.34.0
added 588 packages from 448 contributors and updated 1 package in 23.005s
PS C:\WINDOWS\system32> prisma --version
Prisma CLI version: prisma/1.34.0 (windows-x64) node-v10.9.0

When I try to access the command line interface from a regular cmd/powershell though, the name of the package is not recognized:

C:\Users\XXX>prisma --version
'prisma' is not recognized as an internal or external command,
operable program or batch file.

What do I do to ensure that packages installed from an administrator command line are accessible to the regular command line?

Artem Zakharov
  • 787
  • 1
  • 7
  • 18

1 Answers1

2

Alexey Ivanov answered a similar question a while back, and his answer would help you here. Specifically, the following:

It's worth to mention that NODE_PATH is only used when importing modules in Node apps. When you want to use globally installed modules' binaries in your CLI you need to add it also to your PATH, but without node_modules part (for example %AppData%\npm in Windows 7/8/10).

For that last bit, if your module was installed in "%AppData%\npm\node_modules" your path would include "%AppData%\npm".

Net-net, this isn't a Powershell issue. Its an issue with the package you're installing.

And, if you want a little insight into creating a CLI package, checkout the piece by Rubens Mariuzzo A guide to creating a NodeJS command-line package:

While on Windows, npm will do the same (only if the shebang is specified) but will also create a {command-name}.cmd that calls node to execute our specified command file.

Running Windows 10.0.17763, and I was able to install ‘prisma’ via npm (6.9.0), and I can access it from new console sessions. I was able to do the install both from an elevated and unelevated session w/same result.

enter image description here

Here is what my path looks like after the install:

enter image description here

Adam
  • 3,891
  • 3
  • 19
  • 42
  • This isn't a package specific issue, packages with CLI interfaces are usually accessible just fine after being installed globally, with no manual editing of the path required - the problem here is that a package installed globally from an administrative command line isn't accessible from the regular command line, only other administrative command lines. – Artem Zakharov Jun 30 '19 at 23:25
  • @ArtemZakharov I'm not able to recreate the issue you're describing; see my post for details. I'm seeing everything working just fine. The explanation around where NPM puts things and what it updates isn't because I expect you to manually update elements of the install once complete. It's so you can double check those things and tell us what didn't occur. Since obviously I can install prisma w/o issue following your instructions, we need more information about your specific setup. – Adam Jul 01 '19 at 00:11
  • 1
    I decided to try re-installing NPM entirely, and after doing so (and making sure to check "install all build tools" during the installation) I'm able to call the package from any level of command line without issue... weird. I think I may have been missing some build tools (like Python 2.7) and the re-install restored everything. – Artem Zakharov Jul 01 '19 at 00:27
  • 1
    Nevermind, did a little more experimentation and it turns out I was just missing having something in the system path - I added `%AppData%\npm` to the system PATH variable and it resolved the issue once and for all. – Artem Zakharov Jul 01 '19 at 01:01