从 admin cmd/powershell 安装的软件包未添加到常规 cmd/powershell 的 PATH(无法识别 foo...) [英] Packages installed from admin cmd/powershell not added to PATH for regular cmd/powershell (foo not recognized...)

查看:63
本文介绍了从 admin cmd/powershell 安装的软件包未添加到常规 cmd/powershell 的 PATH(无法识别 foo...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试全局安装一个必须从管理 cmd/powershell 安装的包(它使用 windows-build-tools).当我使用管理 powershell 安装它时,一切正常 - 安装运行没有错误,并且包的命令行界面被添加到路径中:

PS C:\WINDOWS\system32>npm install -g 棱镜C:\Users\XXX\AppData\Roaming\npm\prisma ->C:\Users\XXX\AppData\Roaming\npm\node_modules\prisma\dist\index.js+ 棱镜@1.34.0添加了来自 448 个贡献者的 588 个包并在 23.005 秒内更新了 1 个包PS C:\WINDOWS\system32>棱镜 --versionPrisma CLI 版本:prisma/1.34.0 (windows-x64) node-v10.9.0

当我尝试从常规 cmd/powershell 访问命令行界面时,无法识别包的名称:

C:\Users\XXX>prisma --version'prisma' 不被识别为内部或外部命令,可运行的程序或批处理文件.

如何确保常规命令行可以访问从管理员命令行安装的软件包?

解决方案

Alexey Ivanov 不久前回答了一个类似的问题,并且

这是我安装后的路径:

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?

解决方案

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.

Here is what my path looks like after the install:

这篇关于从 admin cmd/powershell 安装的软件包未添加到常规 cmd/powershell 的 PATH(无法识别 foo...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆