node-gyp: node-gyp is unable to find msbuild if VS2019 is installed.
- Node Version: node 10.15.1 npm 6.4.1
- Platform: Windows Server 2019
- Compiler: msbuild 15.9.21+g9802d43bc3
Verbose output (from npm or node-gyp):
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: D:\a\1\jest\node_modules\weak
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@10.15.1 | win32 | x64
gyp http GET https://nodejs.org/download/release/v10.15.1/node-v10.15.1-headers.tar.gz
gyp http 200 https://nodejs.org/download/release/v10.15.1/node-v10.15.1-headers.tar.gz
gyp http GET https://nodejs.org/download/release/v10.15.1/SHASUMS256.txt
gyp http GET https://nodejs.org/download/release/v10.15.1/win-x86/node.lib
gyp http GET https://nodejs.org/download/release/v10.15.1/win-x64/node.lib
gyp http 200 https://nodejs.org/download/release/v10.15.1/SHASUMS256.txt
gyp http 200 https://nodejs.org/download/release/v10.15.1/win-x86/node.lib
gyp http 200 https://nodejs.org/download/release/v10.15.1/win-x64/node.lib
gyp info spawn C:\ProgramData\Chocolatey\bin\python2.EXE
gyp info spawn args [ 'D:\\a\\1\\jest\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'msvs',
gyp info spawn args '-G',
gyp info spawn args 'msvs_version=2015',
gyp info spawn args '-I',
gyp info spawn args 'D:\\a\\1\\jest\\node_modules\\weak\\build\\config.gypi',
gyp info spawn args '-I',
gyp info spawn args 'D:\\a\\1\\jest\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\VssAdministrator\\.node-gyp\\10.15.1\\include\\node\\common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=C:\\Users\\VssAdministrator\\.node-gyp\\10.15.1',
gyp info spawn args '-Dnode_gyp_dir=D:\\a\\1\\jest\\node_modules\\node-gyp',
gyp info spawn args '-Dnode_lib_file=C:\\Users\\VssAdministrator\\.node-gyp\\10.15.1\\<(target_arch)\\node.lib',
gyp info spawn args '-Dmodule_root_dir=D:\\a\\1\\jest\\node_modules\\weak',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'D:\\a\\1\\jest\\node_modules\\weak\\build',
gyp info spawn args '-Goutput_dir=.' ]
gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\15.0\Bin\MSBuild.exe
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args '/clp:Verbosity=minimal',
gyp info spawn args '/nologo',
gyp info spawn args '/p:Configuration=Release;Platform=x64' ]
I have also tried to install VS2017 build tools on the machine in addition to VS 2019 and node-gyp still tries to find msbuild under the VS2019 install. The issue is due to VS2019 having a different location for msbuild form VS2017. It puts it under C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin instead of C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\15.0\Bin
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 46
- Comments: 36 (4 by maintainers)
My solution was running this command before
npm install
:npm config set msbuild_path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe"
@zhulika @chrisrpatterson I wasn’t comfortable touching
configure.js
plus I needed something that I can use to fix it in our build system now, so I created this temporary workaround in PowerShell. All it does is create a shim:MSBuild\15.0\Bin\MSBuild.exe
->MSBuild\Current\Bin\MSBuild.exe
. Works well for me so far.Updated, here’s how the story continued after upgrading to node-gyp 5.
node-gyp v5.0.0 is out with Visual Studio 2019 support. It’s not yet integrated into npm so it has to be installed manually. This should do it (only need to be run once):
Windows Command Prompt
Powershell
That is, install node-gyp globally and make the npm config variable
node_gyp
point tonode-gyp.js
.How to undo this after node-gyp is integrated into npm
Using yarn instead of npm fixed this for me *shrug*
I’ve just hit this, too. For those who want a temporary workaround, hand-editing the file
configure.js
in node-gyp appears to work. I changed line 161 from this:variables['msbuild_path'] = path.join(vsSetup.path, 'MSBuild', '15.0',
to this:
variables['msbuild_path'] = path.join(vsSetup.path, 'MSBuild', 'Current',
then reran:
node-gyp configure
Fourth point might be redundant. This worked for me, hope it works for you as well. Thanks.
I have sent PR #1715.
as a workaround yes. but I’ve never had MSbuild in my path before.
this seems like a really weird solution but i was able to fix it by doing the following in an administrator powershell:
had this problem on fresh installs of VS 2019 on two different laptops and this has fixed them both.
Apologies if I’m being stupid but I don’t think that this works, either. I ran the script (from a batch file called
install-node-gyp-latest.cmd
that I created from your post):then tried to build a native addin on a machine that has VS2019:
Why is it trying to find MSBuild here:
when it should be looking here:
?
Is there something else that I should have done (obvious to most but I’m new to this so probably not obvious to me)?
As a side note, if we open “Visual Studio cmd for vs2019” and run node-gyp from it, it will detect MSBUILD.exe correctly, but most of the created projects will require v14.1 toolset and default one shipped with vs 2019 is v14.2
Worst issue I’ve run into in a good while. None of the above solved it for me. I had to simply use Visual Studio Installer , to modify installation to include “Desktop Development with C++” option. Simple. Then it explained an error, though it found the precise path of 2019, it was still using a blank msvs_version (despite having configured it previously per above, strange?).
npm config set msvs_version "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise"
Worked instantly.@PaulGG that will cause you issues when uninstalling or updating Node.js, expect node-gyp to stop working in the future. Changing the installation under
C:\Program Files\nodejs\
is always a bad idea.The correct solution for PowerShell is:
Guys this is fixed 2 years ago, you just need to install latest node-gyp globally and set npm to use that, detailed in a cm above:
I’ve done everything i’ve seen on this thread but still doesn’t work, it was working before i updated node to 13.7.0 and i installed VS2019 Professional, i don’t know which of those 2 things broke it
With MSBuild being on the PATH (after running vcvars before compiling), my setup was able to find MSBuild correctly, however, I get the error as above. I ended up having to edit
configure.js
to use the platform toolsetv142
in order to get mine to work.Kind of dumb and late… changing \Enterprise\ to \Community\ worked for me. Should be logic since I don’t have VS Enterprise Edition 😕
Posting this, since this thread helped me, but lost some time figuring out the problem. Sometimes, on this situations, you just go blind to to little details.
@jeromesubs that command is for a cmd shell, but you’re probably getting a PowerShell terminal inside VSCode. Try this one:
for others who do not use VSC Enterprise (I have build tools only) - the my path is
npm config set msbuild_path "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe"