【发布时间】:2021-03-27 14:01:15
【问题描述】:
我正在尝试使用 NPM 安装 windows-build-tools。我从命令提示符尝试了它,它告诉我使用管理 Powershell。所以我在管理员模式下打开了一个 PowerShell 实例(右键单击,“以管理员身份运行”)并重新运行命令:
PS C:\Users\me> npm install -g windows-build-tools
安装失败,提示Please restart this script from an administrative PowerShell!
如何安装这个 npm 包?
这不是与Windows-build-tools installation failed 的重复——该问题建议将 Powershell 添加到路径中,并且我的路径上已经有 Powershell。
除了上面示例中的全局标志外,我还尝试了--production 标志;结果相同。
完整输出:
PS C:\Users\me> npm install -g windows-build-tools
> windows-build-tools@5.2.2 postinstall C:\Users\me\AppData\Roaming\npm\node_modules\windows-build-tools
> node ./dist/index.js
Downloading python-2.7.15.amd64.msi
[> ] 0.0% (0 B/s)
Downloaded python-2.7.15.amd64.msi. Saved to C:\Users\me\.windows-build-tools\python-2.7.15.amd64.msi.
Downloading vs_BuildTools.exe
[> ] 0.0% (0 B/s)
Downloaded vs_BuildTools.exe. Saved to C:\Users\me\.windows-build-tools\vs_BuildTools.exe.
Starting installation...
Please restart this script from an administrative PowerShell!
The build tools cannot be installed without administrative rights.
To fix, right-click on PowerShell and run "as Administrator".
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! windows-build-tools@5.2.2 postinstall: `node ./dist/index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the windows-build-tools@5.2.2 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\me\AppData\Roaming\npm-cache\_logs\2019-07-30T20_46_40_244Z-debug.log
调试日志的相关部分(你可以在第 4 行看到我的 PATH;Powershell 在最后):
4102 silly postinstall windows-build-tools@5.2.2
4103 info lifecycle windows-build-tools@5.2.2~postinstall: windows-build-tools@5.2.2
4104 verbose lifecycle windows-build-tools@5.2.2~postinstall: unsafe-perm in lifecycle true
4105 verbose lifecycle windows-build-tools@5.2.2~postinstall: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\me\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\.bin;C:\Users\me\AppData\Roaming\npm\node_modules\.bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\nodejs\;C:\Users\me\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users\me\AppData\Local\Programs\Python\Python37-32\;C:\Users\me\AppData\Local\Microsoft\WindowsApps;C:\Users\me\AppData\Local\JetBrains\IntelliJ IDEA 2019.2\bin;C:\Users\me\AppData\Local\Programs\Git\cmd;C:\Users\me\AppData\Roaming\npm;C:\windows\system32\WindowsPowerShell\v1.0
4106 verbose lifecycle windows-build-tools@5.2.2~postinstall: CWD: C:\Users\me\AppData\Roaming\npm\node_modules\windows-build-tools
4107 silly lifecycle windows-build-tools@5.2.2~postinstall: Args: [ '/d /s /c', 'node ./dist/index.js' ]
4108 silly lifecycle windows-build-tools@5.2.2~postinstall: Returned: code: 1 signal: null
4109 info lifecycle windows-build-tools@5.2.2~postinstall: Failed to exec postinstall script
4110 timing action:postinstall Completed in 143406ms
4111 verbose unlock done using C:\Users\me\AppData\Roaming\npm-cache\_locks\staging-a76b9d439c0e45ea.lock for C:\Users\me\AppData\Roaming\npm\node_modules\.staging
4112 timing stage:rollbackFailedOptional Completed in 919ms
4113 timing stage:runTopLevelLifecycles Completed in 152174ms
- 节点版本:10.16.0
- NPM 版本:6.9.0
(是的,我很确定我在管理员模式下运行;我的 PowerShell 实例的标题栏显示 Administrator: c:\windows\system32\windowspowershell\v1.0\powershell.exe。)
【问题讨论】:
-
@AlonYeager -- 我的 PATH 上已经有 powershell 路径,这是该问题提供的“解决方案”。
-
Can I ask questions about installation in SO?。程序员常用的软件工具,是软件开发独有的实用、可回答的问题。
-
你找到答案了吗?
标签: npm-install