1 新建powershell脚本文件
<# This is a workaround for "node-gyp is unable to find msbuild if VS2019 is installed" https://github.com/nodejs/node-gyp/issues/1663 It create a shim EXE as "MSBuild\15.0\Bin\MSBuild.exe" to target "MSBuild\Current\Bin\MSBuild.exe" By noseratio - MIT license - use at your own risk! It requires admin mode, I use wsudo/wsudox (https://chocolatey.org/packages/wsudo) for that: wsudo powershell -f make-msbuild-shim.ps1 #> #Requires -RunAsAdministrator #Requires -Version 5.1 $ErrorActionPreference = "Stop" $vsBasePath = . "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" ` -latest ` -requires Microsoft.Component.MSBuild ` -property installationPath -format value if (!$vsBasePath) { throw "VS2017+ must be installed" } $msbuildSimPath = [System.IO.Path]::Combine($vsBasePath, "MSBuild\15.0\Bin\MSBuild.exe") if ([System.IO.File]::Exists($msbuildSimPath)) { Write-Host "Already exists: $msbuildSimPath" exit 0; } # Create the shim .EXE using C# $code = @" using System; using System.Diagnostics; using System.IO; using System.Linq; static class MSBuildShim { static void Main() { var thisExe = Process.GetCurrentProcess().MainModule.FileName; var thisExeDir = Path.GetDirectoryName(thisExe); var newExe = Path.GetFullPath(Path.Combine(thisExeDir, "..\\..\\Current\\Bin", "MSBuild.exe")); if (!File.Exists(newExe)) throw new FileNotFoundException(newExe); var process = new Process(); process.StartInfo.FileName = newExe; process.StartInfo.Arguments = String.Join("\u0020", Environment.GetCommandLineArgs().Skip(1)); process.StartInfo.UseShellExecute = false; if (!process.Start()) throw new InvalidOperationException(newExe); process.WaitForExit(); Environment.ExitCode = process.ExitCode; } } "@ Add-Type -TypeDefinition $code ` -OutputType ConsoleApplication ` -OutputAssembly "$msbuildSimPath" ` -ReferencedAssemblies "System.Core.dll" Write-Host "Shim created at: $msbuildSimPath"
2 打开powershell 执行脚本 生成垫片程序
如果提示禁止执行脚本 则执行 set-executionpolicy remotesigned
附:npm install --global --production windows-build-tools 这个不太好使且只支持2015 2017
3、上述方法试过还是出错,则将2017下相关目录考至2019目录下。方法可以用 cnpm查看具体哪个目录出错。
4、gyp 在 用户目录有 .gyp目录 也有可能报错,删除即可。
参考 :1 http://continuousdeveloper.com/2019/04/09/node-gyp-with-visual-studio-2019/
分类:
js
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
2018-07-23 使用Visual VM 查看linux中tomcat运行时JVM内存