Node-gyp找不到msbuild.exe

您好,我是在Windows上创build本地节点模块的过程,但每当我运行node-gyp build binding.gyp命令我得到一个错误,指出"error: Can't find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008 installed?" 。 我安装了Visual Studio 2013,msbuild目录是C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe. 我尝试添加到PATHvariables,我能够启动cmd提示符,并运行msbuild.exe ,它会返回版本,似乎工作,但由于某种原因node-gyp无法检测到,我甚至尝试修改node-gyp中的build.js文件,使其指向msbuild位置,但失败。

您只能下载构build工具

Microsoft生成工具2013年: http : //www.microsoft.com/en-us/download/details.aspx?id=40760

运行cmd以设置全局标志以使用2013版本:

npm config set msvs_version 2013 --global

在此之后,一切应该恢复正常,你的npm install / node-gyp重build将会工作

我使用了多个修补程序来尝试解决这个问题。 我的版本是:Nodejs 0.12.4(64位),Git 2.5.3,npm 2.10.1,Windows 7和Visual Studio 2013.没有任何工作,直到我试过这个命令:

 npm install -g node-gyp 

但是,下次我试图做到这一点,我收到了同样的错误。 运用

 npm install -g --msvs_version=2013 node-gyp rebuild 

似乎一贯工作。

我希望这有助于某人,因为我已经看到很多问题试图让这个工作在Windows中。

在我的情况下,它给出了以下错误:

 C:\Users\user\DemoApp2\node_modules\bufferutil>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "" rebuild ) gyp ERR! build error gyp ERR! stack Error: Can't find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008+ installed? gyp ERR! stack at findMsbuild (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:128:23) gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:110:11 gyp ERR! stack at F (C:\Program Files\nodejs\node_modules\npm\node_modules\which\which.js:69:16) gyp ERR! stack at E (C:\Program Files\nodejs\node_modules\npm\node_modules\which\which.js:81:29) gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\which\which.js:90:16 gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\which\node_modules\isexe\index.js:44:5 gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\which\node_modules\isexe\windows.js:29:5 gyp ERR! stack at FSReqWrap.oncomplete (fs.js:123:15) gyp ERR! System Windows_NT 10.0.10240 gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" gyp ERR! cwd C:\Users\user\DemoApp2\node_modules\bufferutil gyp ERR! node -v v6.3.1 gyp ERR! node-gyp -v v3.3.1 gyp ERR! not ok npm WARN install:bufferutil@1.2.1 bufferutil@1.2.1 install: `node-gyp rebuild` npm WARN install:bufferutil@1.2.1 Exit status 1 utf-8-validate@1.2.1 install C:\Users\user\DemoApp2\node_modules\utf-8-validate node-gyp rebuild 

所以我按照下面的步骤来解决这个问题:

  1. 首先从以下位置下载并安装Microsoft Build Tools 2013:
    http://www.microsoft.com/en-us/download/details.aspx?id=40760并运行npm config set msvs_version 2013 --global由catalintbuild议。
  2. 删除C:\Users\user下的文件夹.npm-gyp
  3. 执行npm install -g fs --save-dev
  4. 将下载的fs文件夹从C:\Users\user\AppData\Roaming\npm\node_modules$nodehome\node_modules\npm\node_modules (注意:在我的情况下是C:\Program Files\nodejs\node_modules\npm\node_modules
  5. 执行npm install --msvs_version=2013 node-gyp rebuild

做完上述步骤后,我停止了build立错误。