您好我在Windows上创建本机节点模块的过程,但每当我运行该node-gyp build binding.gyp命令时,我都会收到一个错误
"error: Can't find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008 installed?".我安装了Visual Studio 2013,并且C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe.尝试将msbuild目录添加到PATH变量,并且我能够启动cmd提示并运行msbuild.exe它将返回版本,这样看似可行,但由于某种原因,节点 - gyp无法检测到它,我甚至尝试修改node-gyp中的build.js文件,使其指向msbuild位置,但它失败了.
我使用了多个修复程序来尝试解决此问题。我的版本是:Nodejs 0.12.4(64 位)、Git 2.5.3、npm 2.10.1、Windows 7 和 Visual Studio 2013。在我尝试以下命令之前,没有任何效果:
npm install -g node-gyp
Run Code Online (Sandbox Code Playgroud)
然而,下次我尝试这样做时,我收到了同样的错误。使用
npm install -g --msvs_version=2013 node-gyp rebuild
Run Code Online (Sandbox Code Playgroud)
似乎始终如一地工作。
我希望这对某人有所帮助,因为我在尝试在 Windows 中实现此功能时遇到了很多问题。
小智 6
在我的情况下,它给出了以下错误:
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
Run Code Online (Sandbox Code Playgroud)
所以我按照以下步骤来解决这个问题:
npm config set msvs_version 2013 --global 40760并按照 catalint 的建议运行。.npm-gyp下C:\Users\usernpm install -g fs --save-devC:\Users\user\AppData\Roaming\npm\node_modules到$nodehome\node_modules\npm\node_modules(注意:在我的情况下是它C:\Program Files\nodejs\node_modules\npm\node_modules)npm install --msvs_version=2013 node-gyp rebuild 完成上述步骤后,我不再收到构建错误。
您可以只下载构建工具
微软构建工具 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 重建将起作用