Node-gyp无法找到msbuild.exe

13

你好,我正在创建一个本地的Windows节点模块,但是每当我运行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。我尝试将其添加到PATH变量中,并且我可以启动cmd提示符并运行msbuild.exe,它将返回版本,所以似乎工作正常,但由于某种原因node-gyp无法检测到它,我甚至尝试修改node-gyp中的build.js文件,使其指向msbuild位置,但失败了。


@Alan,有关这个问题的任何更新吗? - ShaMoh
这是一个问题,我决定放弃解决它,转而使用另一个开发环境。现在我使用Cloud 9。 - Alan
我正在尝试在本地机器上配置应用程序。有什么建议如何解决这个问题吗? - ShaMoh
4个回答

8

在我的情况下,它会出现以下错误:

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,如catalint所建议。
  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

完成上述步骤后,我不再遇到构建错误。


1
不要使用块引用显示错误,使用代码块以保留格式。 - Alex M

7

我尝试了多种方法来解决这个问题。我的版本是: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上实现此功能的人有所帮助。


1

对我来说,解决方案是在管理员命令提示符下运行此命令:

npm install --global --production windows-build-tools

这实际上卡住了,没有优雅地完成,但我能够使用Ctrl-C关闭它。此后,npm install能够越过node-gyp并在没有错误的情况下完成。


0

您可以仅下载构建工具

Microsoft Build Tools 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 rebuild将会正常工作


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接