node.js 无法在 Windows 7 x64/VS2012 上安装需要编译的节点模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14278417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot install node modules that require compilation on Windows 7 x64/VS2012
提问by Alex Netkachov
I cannot install any of the modules that require compilation. All they fail with the following error:
我无法安装任何需要编译的模块。他们都失败了,并出现以下错误:
MSBUILD : error MSB3411: Could not load the Visual C++ component "VCBuild.exe". ...
My environment:
我的环境:
- Windows 7 Enterprise x64, version 6.1.7601
- node x86 0.8.16
- npm 1.2.0
- node-gyp 0.8.2
- Visual Studio 2012 and numerous packages
- Windows 7 企业版 x64,版本 6.1.7601
- 节点 x86 0.8.16
- 1.2.0
- 节点-gyp 0.8.2
- Visual Studio 2012 和众多软件包
Related environment variables:
相关环境变量:
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.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server0\Tools\Binn\;c:\tools;c:\tools\node
No INCLUDE, LIB, LIBPATH, etc.
没有包含、LIB、LIBPATH 等。
I did a short investigation of the issue and figure out that with the following setup the manual compilation (calling VCBuild.exe and msbuild.exe directly) succeed for the manually cloned git://github.com/einaros/ws.git:
我对这个问题做了一个简短的调查,并发现通过以下设置手动编译(直接调用 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
I've tried to call node-gyp with the same variables and it failed:
我尝试使用相同的变量调用 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 [email protected]
gyp info using [email protected] | 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-gypnpm config set msvs_version 2012 --global
.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-gypnode-gyp rebuild --msvs_version=2012
.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
Maybe you will have some ideas about it?
也许你会对它有一些想法?
Thanks.
谢谢。
回答by srfrnk
Try that - will set it globally:
试试看 - 将它全局设置:
node-gyp configure --msvs_version=2012
node-gyp build
回答by Alex
To do it without VS2010 installation, and only 2012, set the msvs_version flag:
要在不安装 VS2010 且仅安装 2012 的情况下执行此操作,请设置 msvs_version 标志:
node-gyp rebuild --msvs_version=2012
node-gyp rebuild --msvs_version=2012
npm install <module> --msvs_version=2012
npm install <module> --msvs_version=2012
as per @Jacob comment
根据@Jacob 评论
npm install --msvs_version=2013if you have the 2013 version
npm install --msvs_version=2013如果你有 2013 版本
回答by catalint
Update v3: https://www.npmjs.com/package/windows-build-tools
更新 v3:https: //www.npmjs.com/package/windows-build-tools
npm install --global windows-build-tools
npm install --global windows-build-tools
downloads and installs Visual C++ Build Tools 2015, provided free of charge by Microsoft. These tools are required to compile popular native modules. It will also install Python 2.7, configuring your machine and npm appropriately.
下载并安装 Microsoft 免费提供的 Visual C++ Build Tools 2015。编译流行的本机模块需要这些工具。它还将安装 Python 2.7,适当地配置您的机器和 npm。
Update v2:
更新 v2:
node-gyp updated their readme to include HOW-TO for windows
node-gyp 更新了他们的自述文件以包含Windows 的 HOW-TO
Original:
原来的:
No need for the entire visual studio, you can download just the build tools
不需要整个visual studio,你可以只下载构建工具
Microsoft Build Tools 2013 : http://www.microsoft.com/en-us/download/details.aspx?id=40760
Microsoft 构建工具 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
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 重建将起作用
回答by msulhas
just add --msvs_version=2012
只需添加 --msvs_version=2012
npm install --global --production windows-build-tools
or
或者
npm install -g node-gyp -msvs_version=2012
回答by Robin Ridderholt
I had the same issue when trying to install a package for Node.js. After some extensive googeling I found this walktrough: https://github.com/TooTallNate/node-gyp/wiki/Visual-Studio-2010-Setup
我在尝试为 Node.js 安装包时遇到了同样的问题。经过一番广泛的谷歌搜索后,我发现了这个演练:https: //github.com/TooTallNate/node-gyp/wiki/Visual-Studio-2010-Setup
When I had followed these steps I could use "npm install" without any issues.
按照这些步骤操作后,我可以毫无问题地使用“npm install”。
回答by Ramazan Polat
Thanks to @felixrieseberg, you just need to install windows-build-tools npm packageand you are good to go.
感谢@felixrieseberg,您只需要安装windows-build-tools npm 包就可以了。
npm install -g restify
You won't need to install Visual Studio.
你不需要安装 Visual Studio。
You won't need to install Microsoft Build Tools.
您无需安装 Microsoft Build Tools。
From the repo:
从回购:
After installation, npm will automatically execute this module, which downloads and installs Visual C++ Build Tools 2015, provided free of charge by Microsoft. These tools are required to compile popular native modules. It will also install Python 2.7, configuring your machine and npm appropriately.
Windows Vista / 7 requires .NET Framework 4.5.1 (Currently not installed automatically by this package)
Both installations are conflict-free, meaning that they do not mess with existing installations of Visual Studio, C++ Build Tools, or Python.
安装后,npm 会自动执行该模块,该模块会下载并安装 Microsoft 免费提供的 Visual C++ Build Tools 2015。编译流行的本机模块需要这些工具。它还将安装 Python 2.7,适当地配置您的机器和 npm。
Windows Vista / 7 需要 .NET Framework 4.5.1(此包当前未自动安装)
这两种安装都是无冲突的,这意味着它们不会与 Visual Studio、C++ 构建工具或 Python 的现有安装混淆。
回答by amgohan
on windows 8, it worked for me using :
在 Windows 8 上,它对我有用:
Windows 7.1 SDK Command Prompt
then
然后
setenv.cmd /Release /x86
回答by rainabba
After DAYS of digging, someone on IRC suggested that I try to use the
经过几天的挖掘,IRC 上有人建议我尝试使用
$ cd "C:\Program Files\nodejs\node_modules\npm"
$ npm install -g node-gyp@latest
Shortcut (links to C:\Windows\System32\cmd.exe /E:ON /V:ON /T:0E /K "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd"). I think you MUST have the older 7.1 SDK (even on Windows 8.1) because the newer ones use msbuild.exe instead of vcbuild.exe which is what node-gyp wants even though it's twice as old as node at this point :/
快捷方式(链接到 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 的两倍:/
Once in that prompt, I had to run the following to get x86 context because the compiler was throwing as error otherwise about architecture:
进入该提示后,我必须运行以下命令来获取 x86 上下文,因为编译器在其他情况下抛出有关架构的错误:
##代码##THEN I was able to successfully run npm commands that were trying to use node-gyp to recompile things.
然后我能够成功运行试图使用 node-gyp 重新编译东西的 npm 命令。
回答by amitgur
I had the same isuee and did all the magic above, the only thing that did the magic for me is from https://github.com/atom/atom/issues/2435
我有同样的 isuee 并做了上面所有的魔法,唯一对我有用的东西来自https://github.com/atom/atom/issues/2435
"Because the --msvs_version=2013 is not passed to node-gyp when it's run by the build script. Set the GYP_MSVS_VERSION = 2013 env variable and it should work after."
“因为 --msvs_version=2013 在构建脚本运行时不会传递给 node-gyp。设置 GYP_MSVS_VERSION = 2013 环境变量,它应该在之后工作。”
Bang! it worked
砰! 有效
回答by danielpopa
On Windows This helped me: (credits goes to) https://github.com/TooTallNate/node-gyp/wiki/Updating-npm%27s-bundled-node-gypI tried MINGW32, but with no success.
在 Windows 这对我有帮助:(学分转到)https://github.com/TooTallNate/node-gyp/wiki/Updating-npm%27s-bundled-node-gyp我尝试了 MINGW32,但没有成功。
on cmd.exe
在 cmd.exe

