安装了vs2019 编译node-sass node-gyp 找不到编译器的解决方法
2021/7/23 9:35:45
本文主要是介绍安装了vs2019 编译node-sass node-gyp 找不到编译器的解决方法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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/
2 https://blog.csdn.net/ebzxw/article/details/85019887
这篇关于安装了vs2019 编译node-sass node-gyp 找不到编译器的解决方法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-22项目:远程温湿度检测系统
- 2024-12-21《鸿蒙HarmonyOS应用开发从入门到精通(第2版)》简介
- 2024-12-21后台管理系统开发教程:新手入门全指南
- 2024-12-21后台开发教程:新手入门及实战指南
- 2024-12-21后台综合解决方案教程:新手入门指南
- 2024-12-21接口模块封装教程:新手必备指南
- 2024-12-21请求动作封装教程:新手必看指南
- 2024-12-21RBAC的权限教程:从入门到实践
- 2024-12-21登录鉴权实战:新手入门教程
- 2024-12-21动态权限实战入门指南