我遇到的问题是我无法安装项目的软件包,它一直出错:
npm ERR! npm ERR! gyp ERR! find VS valid versions for msvs_version:
npm ERR! npm ERR! gyp ERR! find VS
npm ERR! npm ERR! gyp ERR! find VS **************************************************************
npm ERR! npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! npm ERR! gyp ERR! find VS **************************************************************
Run Code Online (Sandbox Code Playgroud)
我尝试遵循其他人的这些线索的建议:
如何修复 Node.js 错误,例如“gyp ERR!找到 VS,包括“使用 C++ 进行桌面开发”工作负载。” 当我启动 Nuxt.js 项目时
这我该如何解决错误 gypgyp ERR!ERR! 发现 VSfind VS msvs_version 未从命令行或 npm 配置设置?
但似乎都没有帮助。
到目前为止我所做的:
我安装了最新的 VS Code(2022 社区)Desktop development with C++以及MSVC v143 - VS 2022 C++ x64/x86 build tools
我已配置msvs_version为具有 的值2022,我使用npm config set msvs_version=2022和 执行此操作node-gyp configure --msvs_version=2022
我尝试过安装 Windows 构建工具npm install --global --production windows-build-tools,但它只是说...Node.js now incldues build tools for Windows...
我还使用上面列出的第二篇文章中的命令手动构建了node-gyp,node-gyp configure node-gyp configure --msvs_version=2022 node-gyp build并且一切顺利
我不知道我还能做什么
解决了 Windows 11、VSCode、Visual Studio 2022 中的 node-gyp
node -v
v18.4.0
nvm version
1.1.9
node-gyp -v
v9.0.0
node-gyp configure --msvs_version=2022
Run Code Online (Sandbox Code Playgroud)
启动 Visual Studio 安装程序
在 Visual Studio Community 2022 -> 修改 -> 各个组件旁边键入 Visual C++
确保选中 MSVC v143 ... x64/x86 构建工具(最新)。
检查当前的 Windows 版本
返回 Visual Studio 安装,键入 SDK,然后找到正确的 SDK 版本。对我来说,Windows 11 SDK (10.0.22000.0)
经过所有这些设置..我仍然得到
gyp ERR! find VS - does not match this Visual Studio Command Prompt
Run Code Online (Sandbox Code Playgroud)
知道我必须破解代码
在错误日志上方添加这 3 行
+this.addLog("this.envVcInstallDir: " + this.envVcInstallDir)
+this.addLog("vsPath: " + vsPath)
+this.addLog("path.relative(this.envVcInstallDir, vsPath): " + path.relative(this.envVcInstallDir, vsPath))
if (this.envVcInstallDir &&
path.relative(this.envVcInstallDir, vsPath) !== '') {
this.addLog('- does not match this Visual Studio Command Prompt')
return false
}
Run Code Online (Sandbox Code Playgroud)
并追踪到
if (process.env.VCINSTALLDIR) {
this.envVcInstallDir =
path.resolve(process.env.VCINSTALLDIR, '..')
this.addLog('running in VS Command Prompt, installation path is:\n' +
`"${this.envVcInstallDir}"\n- will only use this version`)
} else {
this.addLog('VCINSTALLDIR not set, not running in VS Command Prompt')
}
Run Code Online (Sandbox Code Playgroud)
最后,必须在 VCINSTALLDIR 末尾添加一些内容
问题已解决,将卸载 VS 2017 和 2019 以节省空间。
| 归档时间: |
|
| 查看次数: |
28185 次 |
| 最近记录: |