npm install failed by gyp verb 在 PATH 中找不到 "msbuild.exe" - 在注册表中查找位置

npm install failed by gyp verb could not find "msbuild.exe" in PATH - finding location in registry

我在执行npm install命令时遇到这个问题

我尝试将 MSBuild.exe 添加到 PATH 但无法成功

我该如何处理这个问题?

在我添加到 python2 路径之前,并尝试了 npm install --global --production windows-build-tools

npm ERR! gyp verb command build []
npm ERR! gyp verb build type Release
npm ERR! gyp verb architecture x64
npm ERR! gyp verb node dev dir C:\Users\fzc\.node-gyp.5.0
npm ERR! gyp verb found first Solution file build/binding.sln
npm ERR! gyp verb could not find "msbuild.exe" in PATH - finding location in registry
npm ERR! gyp info spawn C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   'build/binding.sln',
npm ERR! gyp info spawn args   '/nologo',
npm ERR! gyp info spawn args   '/p:Configuration=Release;Platform=x64'
npm ERR! gyp info spawn args ]
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onExit (C:\Users\fzc\code\nx-admin\node_modules\node-gyp\lib\build.js:262:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! gyp ERR! System Windows_NT 10.0.19042
npm ERR! gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\fzc\code\nx-admin\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd C:\Users\fzc\code\nx-admin\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.5.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1

对我来说,从具有管理员权限的命令行 运行ning npm i -g windows-build-tools 会在安装过程中挂起,但我能够导航到 C:\Users\[username]\.windows-build-tools 和 运行 vs_BuildTools.exe 文件。这发挥了它的魔力,我能够像往常一样 运行 npm install