如何修复错误:spawnSync powershell.exe无效

时间:2019-09-02 01:40:03

标签: node.js powershell npm-install enoent

我想使用以下命令通过提升的PowerShell控制台安装Windows构建工具:

as!

但是每次我运行上面的npm install --global --production windows-build-tools 命令时,我都会得到以下错误信息:

windows-build-tools@5.2.2 postinstall C:\Users\AKA\AppData\Roaming\npm\node_modules\windows-build-tools> node ./dist/index.js

C:\Users\AKA\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\in-gfw\lib\os.js:53
                        throw resultError;
                        ^

Error: spawnSync powershell.exe ENOENT
    at Object.spawnSync (internal/child_process.js:1002:20)
    at Object.spawnSync (child_process.js:614:24)
    at spawnSync (C:\Users\AKA\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\in-gfw\lib\geo.js:67:36)
    at Object.queryRegFromPowershell (C:\Users\AKA\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\in-gfw\lib\geo.js:73:3)
    at loop (C:\Users\AKA\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\in-gfw\lib\geo.js:113:16)
    at opts.shift (C:\Users\AKA\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\in-gfw\lib\geo.js:116:7)
    at spawn (C:\Users\AKA\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\in-gfw\lib\geo.js:100:5)
    at spawnSync (C:\Users\AKA\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\in-gfw\lib\geo.js:68:2)
    at Object.queryRegFromRegExe (C:\Users\AKA\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\in-gfw\lib\geo.js:96:3)
    at loop (C:\Users\AKA\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\in-gfw\lib\geo.js:113:16)
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\AKA\AppData\Roaming\npm-cache\_logs\2019-09-02T01_30_08_978Z-debug.log
PS> node -v
10.16.0
PS> npm -v 
6.9.0

1 个答案:

答案 0 :(得分:6)

将%SystemRoot%/ system32 / WindowsPowerShell / v1.0添加到PATH变量中,

  1. cmd + q并搜索环境,然后按Enter键
  2. 在高级标签中点击环境变量
  3. 找到“路径/ PATH”变量,然后单击“编辑”
  4. 单击新建,然后粘贴%SystemRoot%/ system32 / WindowsPowerShell / v1.0
  5. 单击“确定”,然后重新启动终端,然后尝试重新安装