简体   繁体   English

Node-gyp 找不到 msbuild.exe

[英]Node-gyp cannot find msbuild.exe

Hello I am on the processes of creating a native node module on windows, but whenever I ran the node-gyp build binding.gyp command I obtain an error that states "error: Can't find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008 installed?"您好,我正在 windows 上创建本机节点模块的过程,但是每当我运行node-gyp build binding.gyp gyp build binding.gyp 命令时,我都会收到一条错误消息,指出"error: Can't find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008 installed?" . . I have Visual Studio 2013 installed and the msbuild directory is C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe.我安装了 Visual Studio 2013,并且 msbuild 目录是C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe. I tried adding that to the PATH variable, and I am able to start a cmd prompt and run msbuild.exe and it will return the version so that seems to be working, but for some reason node-gyp cannot detect it, I even attempted to modify the build.js file within node-gyp to have it point to the msbuild location but it fails.我尝试将其添加到 PATH 变量中,并且我能够启动 cmd 提示并运行msbuild.exe它将返回版本,因此似乎可以正常工作,但由于某种原因 node-gyp 无法检测到它,我什至尝试过修改 node-gyp 中的 build.js 文件,使其指向 msbuild 位置,但它失败了。

In my case it was giving below error : 在我的情况下,它给出了以下错误:

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

So i followed below steps to fix the issue : 所以我按照以下步骤来解决问题:

  1. Firstly download and install Microsoft Build Tools 2013 from : 首先从以下位置下载并安装Microsoft Build Tools 2013:
    http://www.microsoft.com/en-us/download/details.aspx?id=40760 and run npm config set msvs_version 2013 --global as suggested by catalint. http://www.microsoft.com/en-us/download/details.aspx?id=40760npm config set msvs_version 2013 --global建议运行npm config set msvs_version 2013 --global --global。
  2. Delete the folder .npm-gyp under C:\\Users\\user\u003c/code> 删除C:\\Users\\user\u003c/code>下的文件夹.npm-gyp
  3. execute npm install -g fs --save-dev 执行npm install -g fs --save-dev
  4. Copy the downloaded fs folder from C:\\Users\\user\\AppData\\Roaming\\npm\\node_modules to $nodehome\\node_modules\\npm\\node_modules (Note : In my case its C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules ) 将下载的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. execute npm install --msvs_version=2013 node-gyp rebuild 执行npm install --msvs_version=2013 node-gyp rebuild

After doing above steps i stopped getting build errors. 完成上述步骤后,我停止了构建错误。

I used multiple fixes to try and get this resolved. 我使用了多个修复程序来尝试解决这个问题。 My versions are: Nodejs 0.12.4 (64 bit), Git 2.5.3, npm 2.10.1, Windows 7, and Visual Studio 2013. Nothing worked until I tried this command: 我的版本是:Nodejs 0.12.4(64位),Git 2.5.3,npm 2.10.1,Windows 7和Visual Studio 2013.在我尝试此命令之前没有任何工作:

npm install -g node-gyp

However, the next time I tried to do this I received the same error. 但是,下次我尝试这样做时,我收到了同样的错误。 Using 运用

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

seems to work consistently. 似乎一贯工作。

I hope this helps someone as I've seen lots of problems trying to get this working in windows. 我希望这有助于某人,因为我已经看到很多问题试图让这个在Windows中工作。

You can download just the build tools 您只需下载构建工具即可

Microsoft Build Tools 2013 : http://www.microsoft.com/en-us/download/details.aspx?id=40760 Microsoft Build Tools 2013: http//www.microsoft.com/en-us/download/details.aspx?id = 40760

run cmd to set global flag to use the 2013 version: 运行cmd以设置全局标志以使用2013版本:

npm config set msvs_version 2013 --global

after this everything should be back to normal and your npm install / node-gyp rebuild will work 在这之后一切都应该恢复正常,你的npm install / node-gyp rebuild将会起作用

For me, the solution was to run this at an admin command prompt:对我来说,解决方案是在管理员命令提示符下运行它:

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

This actually got stuck and didn't finish gracefully, but I was able to close it using Ctrl-C.这实际上卡住了并且没有优雅地完成,但我能够使用 Ctrl-C 关闭它。 After that npm install was able to get past node-gyp and finished without errors.之后npm install能够通过 node-gyp 并完成而没有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM