Node Gyp with Visual Studio 2019

I'm working on an Angular application and had to recently re-install my node_modules. This means installing node-sass which in turn uses node-gyp (python and c++) to build some native modules.

The node-gyp build kept failing as it couldn't find the MSBuild.exe in the location it expected. Turns out the in Visual Studio 2019, the location (and convention) has changed.

I see that it's an open issue on the node-gyp repo, with an open PR.

But in the meantime, I found a comment on the issue where someone wrote a nifty Powershell script that creates a shim EXE in the location node-gyp expects, but forwards the command to the actual msbuild.exe. Problem solved until it can be fixed properly.

You can find the script here:

  1. Copy it into a text document and name something like create-msbuild-shim.ps1
  2. Open a PowerShell prompt as Administrator
  3. .\create-msbuild-shim.ps1
  4. Re-run your npm install or node-gyp rebuild