NPM 错误!1 NPM 错误!安装软件包时

NPM Err! 1 NPM ERR! When installing package

提问人:Vinicius Leite 提问时间:11/14/2023 最后编辑:Vinicius Leite 更新时间:11/15/2023 访问量:106

问:

当我尝试安装软件包“node-red-node-arduino”时,我收到此错误。以下是完整日志:

PS C:\Users\User\.node-red> npm i --unsafe-perm node-red-node-arduino
npm ERR! code 1
npm ERR! path C:\Users\User\.node-red\node_modules\@serialport\bindings
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp info find Python using Python version 3.12.0 found at "C:\Users\User\AppData\Local\Programs\Python\Python312\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
npm ERR! gyp ERR! find VS not looking for VS2015 as it is only supported up to Node.js 18
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:122:47)
npm ERR! gyp ERR! stack     at C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:75:16
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:380:14)
npm ERR! gyp ERR! stack     at C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:71:14
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2015 (C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:364:14)
npm ERR! gyp ERR! stack     at C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:67:12
npm ERR! gyp ERR! stack     at failPowershell (C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:156:7)
npm ERR! gyp ERR! stack     at VisualStudioFinder.parseData (C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:170:14)
npm ERR! gyp ERR! stack     at C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:143:14
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:414:7)
npm ERR! gyp ERR! System Windows_NT 10.0.19045
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\User\\AppData\\Roaming\\nvm\\v20.9.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\User\.node-red\node_modules\@serialport\bindings
npm ERR! gyp ERR! node -v v20.9.0
npm ERR! gyp ERR! node-gyp -v v9.4.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in: C:\Users\User\AppData\Local\npm-cache\_logs\2023-11-14T13_20_45_527Z-debug-0.log

我已经通过 NVM 安装了 node 和 NPM,通过命令“nvm install 20.9.0”,20.9.0 是他们所说的节点的最后一个稳定版本。

编辑1: 安装了 VS Code 并重新启动了计算机,但仍然得到这个结果:

PS C:\Users\User\.node-red> npm i -g --unsafe-perm node-red-node-arduino
npm ERR! code 1
npm ERR! path C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\node-red-node-arduino\node_modules\@serialport\bindings
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp info find Python using Python version 3.12.0 found at "C:\Users\User\AppData\Local\Programs\Python\Python312\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
npm ERR! gyp ERR! find VS not looking for VS2015 as it is only supported up to Node.js 18
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:122:47)
npm ERR! gyp ERR! stack     at C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:75:16
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:380:14)
npm ERR! gyp ERR! stack     at C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:71:14
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2015 (C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:364:14)
npm ERR! gyp ERR! stack     at C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:67:12
npm ERR! gyp ERR! stack     at failPowershell (C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:156:7)
npm ERR! gyp ERR! stack     at VisualStudioFinder.parseData (C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:170:14)
npm ERR! gyp ERR! stack     at C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:143:14
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:414:7)
npm ERR! gyp ERR! System Windows_NT 10.0.19045
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\User\\AppData\\Roaming\\nvm\\v20.9.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\User\AppData\Roaming\nvm\v20.9.0\node_modules\node-red-node-arduino\node_modules\@serialport\bindings
npm ERR! gyp ERR! node -v v20.9.0
npm ERR! gyp ERR! node-gyp -v v9.4.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in: C:\Users\User\AppData\Local\npm-cache\_logs\2023-11-14T16_45_22_153Z-debug-0.log
节点.js windows npm npm-install node-red

评论

4赞 esqew 11/14/2023
您是否真的安装了Visual Studio,因为错误恳求您这样做?
0赞 esqew 11/14/2023
20.9.0 是他们所说的 Node 的最后一个稳定版本。”他们”是谁?不管是谁,“他们”都错了 - 节点 21 是稳定且普遍可用的,主要区别在于节点 21 不像节点 20 那样是 LTS 版本。
0赞 Vinicius Leite 11/15/2023
@esqew根据“NVM list available”命令回答的内容,它是最新的 LTS。
0赞 Vinicius Leite 11/15/2023
@esqew更新了问题。
2赞 esqew 11/15/2023
VS Code 不是 Visual Studio - 它们是两个截然不同的东西。按照错误中提供的链接并安装错误消息中提到的软件包。

答:

0赞 Vinicius Leite 11/15/2023 #1

npm 错误!哎呀呀!查找 VS,包括“使用 C++ 进行桌面开发”工作负载。 npm 错误!哎呀呀!查找 VS 有关更多信息,请参阅以下文档:

如此处所述,我必须安装 Visual Studio(不是 VS 代码,因为我一开始很艰难)选中安装“使用 C++ 进行桌面开发”的选项

Visual Studio Window with the options of installation expanded and an arrow pointing to the checkbox of "Desktop development with C++"

感谢@esqew,他帮助我找到了解决方案。