【问题标题】:Node-gyp cannot find msbuild.exeNode-gyp 找不到 msbuild.exe
【发布时间】:2015-03-31 20:40:21
【问题描述】:

您好,我正在 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 有什么更新吗??
  • 这是我决定转移到另一个开发环境而不是解决它的问题之一。我现在使用云 9
  • 我正在尝试在本地机器上配置应用程序。有什么建议可以解决这个问题吗??

标签: node.js path


【解决方案1】:

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

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. 首先从 :
    http://www.microsoft.com/en-us/download/details.aspx?id=40760 下载并安装 Microsoft Build Tools 2013 和 按照建议运行npm config set msvs_version 2013 --global Catalint。
  2. 删除.npm-gyp下的文件夹C:\Users\user
  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

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

【讨论】:

  • 不要使用块引用来表示错误,使用代码块来保留格式。
【解决方案2】:

我使用了多个修复程序来尝试解决这个问题。我的版本是: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 中工作。

【讨论】:

    【解决方案3】:

    您可以只下载构建工具

    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 rebuild 将工作

    【讨论】:

      猜你喜欢
      • 2022-08-03
      • 2016-01-09
      • 2018-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-26
      • 2018-01-29
      相关资源
      最近更新 更多