193

我无法安装任何需要编译的模块。他们都失败并出现以下错误:

MSBUILD : error MSB3411: Could not load the Visual C++ component "VCBuild.exe". ...

我的环境:

  • Windows 7 企业版 x64,版本 6.1.7601
  • 节点 x86 0.8.16
  • npm 1.2.0
  • 节点gyp 0.8.2
  • Visual Studio 2012 和众多软件包

相关环境变量:

Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShel l\v1.0;C:\Program Files\TortoiseGit\bin;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;c:\tools;c:\tools\node

没有 INCLUDE、LIB、LIBPATH 等。

我对该问题进行了简短调查,并发现通过以下设置手动编译(直接调用 VCBuild.exe 和 msbuild.exe)对于手动克隆的 git://github.com/einaros/ws.git 成功:

SET Configuration=Release
SET PATH=%ProgramFiles(x86)%\Microsoft Visual Studio 9.0\VC\vcpackages
SET PATH=%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\bin;%PATH%
SET PATH=%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\Common7\IDE;%PATH%
SET PATH=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Bin;%PATH%
SET PATH=%SystemRoot%\system32;%PATH%

SET INCLUDE=%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\include
SET INCLUDE=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Include;%INCLUDE%

SET LIB=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Lib
SET LIB=%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\lib;%LIB%

SET MSBUILD="%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"

VCBuild.exe C:\Tools\node\ws\build\bufferutil.vcproj "Release|Win32" /useenv
VCBuild.exe C:\Tools\node\ws\build\validation.vcproj "Release|Win32" /useenv
%MSBUILD% build/binding.sln /verbosity:diagnostic /nologo /p:Configuration=Release;Platform=Win32

我尝试使用相同的变量调用 node-gyp,但失败了:

C:\!> git clone https://github.com/einaros/ws.git
C:\!> cd ws
C:\!\ws>node-gyp configure
...
C:\!\ws>node-gyp build
gyp info it worked if it ends with ok
gyp info using node-gyp@0.8.2
gyp info using node@0.8.16 | win32 | ia32
gyp info spawn C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args   '/clp:Verbosity=minimal',
gyp info spawn args   '/nologo',
gyp info spawn args   '/p:Configuration=Release;Platform=Win32' ]
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Users\User\.node-gyp\0.8.16\deps\uv\include\uv.h(55): fatal error C1083: Cannot open include file: 'stdint.h': No such file or directory [C:\!\
ws\build\binding.sln]
C:\Users\User\.node-gyp\0.8.16\deps\uv\include\uv.h(55): fatal error C1083: Cannot open include file: 'stdint.h': No such file or directory [C:\!\
ws\build\binding.sln]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (c:\Tools\node\node_modules\node-gyp\lib\build.js:255:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:99:17)
gyp ERR! stack     at Process._handle.onexit (child_process.js:678:10)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "c:\\Tools\\node\\\\node.exe" "c:\\Tools\\node\\node_modules\\node-gyp\\bin\\node-gyp.js" "build"
gyp ERR! cwd C:\!\ws
gyp ERR! node -v v0.8.16
gyp ERR! node-gyp -v v0.8.2
gyp ERR! not ok

也许你会对它有一些想法?

谢谢。

4

17 回答 17

151

试试看 - 将它全局设置:

npm config set msvs_version 2012 --global
于 2014-03-14T16:44:19.297 回答
144

要在不安装 VS2010 且仅 2012 的情况下执行此操作,请设置 msvs_version 标志:

node-gyp rebuild --msvs_version=2012

npm install <module> --msvs_version=2012

根据@Jacob 评论

npm install --msvs_version=2013如果你有 2013 版

于 2013-05-31T09:40:43.920 回答
60

更新 v3: https ://www.npmjs.com/package/windows-build-tools

npm install --global windows-build-tools

下载并安装 Microsoft 免费提供的 Visual C++ Build Tools 2015。这些工具是编译流行的本机模块所必需的。它还将安装 Python 2.7,适当地配置您的机器和 npm。

更新 v2:

node-gyp 更新了他们的自述文件以包括Windows 的 HOW-TO

原来的:

不需要整个视觉工作室,你可以只下载构建工具

微软构建工具 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 将工作

于 2015-08-13T11:39:27.590 回答
41

只需添加 --msvs_version=2012

node-gyp rebuild --msvs_version=2012

或者

node-gyp configure --msvs_version=2012
node-gyp build 
于 2013-04-14T15:14:37.870 回答
21

尝试为 Node.js 安装包时遇到了同样的问题。经过一番广泛的谷歌搜索后,我发现了这个演练:https ://github.com/TooTallNate/node-gyp/wiki/Visual-Studio-2010-Setup

当我按照这些步骤操作时,我可以毫无问题地使用“npm install”。

于 2013-04-05T09:57:18.540 回答
13

感谢@felixrieseberg,您只需要安装windows-build-tools npm 包就可以了。

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

您无需安装 Visual Studio。

您无需安装 Microsoft Build Tools。

从回购:

安装后,npm 会自动执行该模块,下载并安装微软免费提供的 Visual C++ Build Tools 2015。这些工具是编译流行的本机模块所必需的。它还将安装 Python 2.7,适当地配置您的机器和 npm。

Windows Vista / 7 需要 .NET Framework 4.5.1(目前此软件包不会自动安装)

两种安装都没有冲突,这意味着它们不会与 Visual Studio、C++ 构建工具或 Python 的现有安装混淆。

于 2016-11-15T17:18:47.157 回答
12

在 Windows 8 上,它对我有用:

npm install -g node-gyp -msvs_version=2012

然后

npm install -g restify
于 2014-01-29T03:55:38.083 回答
5

经过几天的挖掘,IRC 上的某个人建议我尝试使用

Windows 7.1 SDK Command Prompt

快捷方式(链接到 C:\Windows\System32\cmd.exe /E:ON /V:ON /T:0E /K "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" )。我认为您必须拥有较旧的 7.1 SDK(即使在 Windows 8.1 上),因为较新的 SDK 使用 msbuild.exe 而不是 vcbuild.exe,这是 node-gyp 想要的,即使它现在是 node 的两倍:/

一旦出现该提示,我必须运行以下命令来获取 x86 上下文,因为编译器会抛出有关体系结构的错误:

setenv.cmd /Release /x86

然后我能够成功运行试图使用 node-gyp 重新编译东西的 npm 命令。

于 2013-12-05T19:02:41.700 回答
4

我有相同的 isuee 并做了上面所有的魔法,唯一对我有魔法的是来自https://github.com/atom/atom/issues/2435

“因为 --msvs_version=2013 在由构建脚本运行时没有传递给 node-gyp。设置 GYP_MSVS_VERSION = 2013 环境变量,它应该在之后工作。”

砰! 有效

于 2015-05-24T08:07:27.730 回答
3

在 Windows 上这对我有帮助:(学分转到)https://github.com/TooTallNate/node-gyp/wiki/Updating-npm%27s-bundled-node-gyp 我尝试了 MINGW32,但没有成功。

cmd.exe

$ cd "C:\Program Files\nodejs\node_modules\npm"
$ npm install -g node-gyp@latest
于 2014-09-20T18:02:21.657 回答
2

对于 Windows 8 64 位,安装 zmq 和 protobuf,以下对我有用: 在命令行上安装Visual Studio 2012 :

SET VisualStudioVersion=11.0
npm install zmq
npm install protobuf
于 2013-11-01T22:01:12.313 回答
1

我认为解决方案是下载 安装 Microsoft windows sdk for server 2008 with .net framework 3.5

或者只是安装 Visual Studio 2008

问题是 Windows 构建 node-gyp 执行 vcbuid.exe 文件,由于某种原因它找不到它。

谢谢

于 2013-03-05T13:08:16.283 回答
1
  1. 安装 Python 2.7(不是 3.x)
  2. 将路径添加到包含vcbuild.exe在您的环境变量中的目录PATH
  3. 如果你需要vcbuild.exe在这里 https://github.com/kin9puppy/vcbuildFixForNode
于 2015-05-27T16:36:22.343 回答
0

我在编译nodejs zmq时也遇到了很多问题。

对于 vcbuild.exe 的问题,只需将其添加到 PATH

对于其他问题,我可以只使用编译Windows 7.1 SDK Command Prompt

(菜单程序 -> Microsoft Windows SDK v7.1 -> Windows 7.1 SDK 命令提示符)

并根据提示:

npm install zmq

那行得通:)

于 2014-09-23T18:17:54.797 回答
0

在 cmd 中根据您的版本设置 Visual Studio 路径为

Visual Studio 2010 (VS10): SET VS90COMNTOOLS=%VS100COMNTOOLS%

Visual Studio 2012 (VS11): SET VS90COMNTOOLS=%VS110COMNTOOLS%

Visual Studio 2013 (VS12): SET VS90COMNTOOLS=%VS120COMNTOOLS%

在 node-master(从 gi​​t 下载的原始节点模块)中以管理员权限运行vcbuild.bat 。vcbild.bat 会生成windows相关的依赖,会在node-master中添加文件夹名Release

一旦运行,构建文件需要时间。

然后在具有 .gyp 文件的目录中使用命令

node-gyp rebuild --msvs_version=2012 --nodedir="Dive Name:\path to node-master\node-master"

这将构建所有依赖项。

于 2015-04-14T15:14:07.533 回答
0

经过长时间的斗争,我将节点架构切换到 x86,它的工作原理非常棒。

于 2014-06-06T07:33:13.923 回答
0

我通过本教程在 windows 8 和 windows 10 pro 上解决了这个问题。我尝试了很多次用许多不同的解决方案来解决这个问题,但只对我有用: http ://www.serverpals.com/blog/building-using-node-gyp-with-visual-studio-express -2015-on-windows-10-pro-x64 我注意到我没有像本教程那样使用 nodist 来控制节点版本,我使用 NVM 并且工作正常,我没有使用 nodist 测试本教程。我使用节点 5.2.0。

于 2015-12-28T16:50:29.223 回答