如何让node-gyp在Windows 7平台上工作

前端之家收集整理的这篇文章主要介绍了如何让node-gyp在Windows 7平台上工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在尝试编译标准的“Hello World”示例[2]时,我尝试在Windows 7 Node.js平台上使用node-gyp失败[3].注意:在尝试npm安装contextify w或w-o“-g”时,node-gyp以类似的方式失败[3],因此这些可能是相关问题.

组态:

> node-gyp 0.12.2
> Windows 7 x64 SP1
> Python 2.7
> Node.js 0.10.24
> Visual Studio 2010 / [1](也试过2012)
> VS SDK 7.1 / [1](尝试32位和64位版本)
>从标准Windows命令提示符或SDK7.1 cmd提示符运行node-gyp

参考文献:
[1] https://github.com/TooTallNate/node-gyp/wiki/Visual-Studio-2010-Setup

[2] https://github.com/joyent/node/tree/master/test/addons/hello-world

[3]“hello world”[2]项目中的“node-gyp rebuild”产生以下2个错误

….node-gyp\0.10.24\deps\uv\include\win.h(8738): error C2371: ‘SYSTEM_POWER_STATUS’ : redefinition; different basic types […\build\test.vcxproj]

….node-gyp\0.10.24\deps\uv\include\mswsock.h(27): fatal error C
1083: Cannot open include file: ‘_mingw.h’: No such file or directory […\build\test.vcxproj]

并发出以下2个警告:

….node-gyp\0.10.24\deps\uv\include\win.h(13513): warning C4005:
‘UNALIGNED’ : macro redefinition […\build\test.vcxproj]

….node-gyp\0.10.24\deps\uv\include\mswsock.h(26): warning C4068
: unknown pragma […\build\test.vcxproj]

完整的追踪如下:

C:\sigma\node_modules\x>node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@0.12.2
gyp info using node@0.10.24 | win32 | x64
gyp info spawn python
gyp info spawn args [ 'C:\\Users\\Anybody\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',gyp info spawn args   'binding.gyp',gyp info spawn args   '-f',gyp info spawn args   'msvs',gyp info spawn args   '-G',gyp info spawn args   'msvs_version=auto',gyp info spawn args   '-I',gyp info spawn args   'C:\\sigma\\node_modules\\x\\build\\config.gypi',gyp info spawn args   'C:\\Users\\Anybody\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',gyp info spawn args   'C:\\Users\\Anybody\\.node-gyp\\0.10.24\\common.gypi',gyp info spawn args   '-Dlibrary=shared_library',gyp info spawn args   '-Dvisibility=default',gyp info spawn args   '-Dnode_root_dir=C:\\Users\\Anybody\\.node-gyp\\0.10.24',gyp info spawn args   '-Dmodule_root_dir=C:\\sigma\\node_modules\\x',gyp info spawn args   '--depth=.',gyp info spawn args   '--generator-output',gyp info spawn args   'C:\\sigma\\node_modules\\x\\build',gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn msbuild
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=x64' ]
Building the projects in this solution one at a time. To enable parallel build,please add the "/m" switch.  test.cpp
C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\win.h(8738): error C2371: 'SYSTEM_POWER_STATUS' : redefinition; different basic types [C:\sigma\node_modules\x\build\test.vcxproj]  C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\win.h(8737) : see declaration of 'SYSTEM_POWER_STATUS'

C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\win.h(13513): warning C4005: 'UNALIGNED' : macro redefinition [C:\sigma\node_modules\x\build\test.vcxproj] C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdef s.h(502) : see prevIoUs definition of 'UNALIGNED'

C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\mswsock.h(26): warning C4068 : unknown pragma [C:\sigma\node_modules\x\build\test.vcxproj] C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\_mingw.h(33): warning C4068: unknown pragma [C:\sigma\node_modules\x\build\test.vcxproj]

C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\_mingw.h(51): fatal error C1 189: #error :  ERROR: You must use a GNU Compiler. [C:\sigma\node_modules\x\build\test.vcxproj]

gyp ERR! build error
gyp ERR! stack Error: msbuild Failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Users\Anybody\AppData\Roaming\npm\
node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Users\\Anybody\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\sigma\node_modules\x
gyp ERR! node -v v0.10.24
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
虽然这个问题是一个月大的时间,但我最终在网路上搜索,这是搜索结果的一部分.

所以这里是一个不应该做的但是它的作品答案.

首先,我不熟悉node-gyp或整个visual studio编译和东西,我真的很感到遗憾的是,依赖于python(一个非常无声的WTF)的node-gyp,

所以没有已知的原因nodejs版本早于0.10.22(我现在运行,所以我假定它在哪里开始)

如果您搜索系统中的文件“uv.h”,您可能会得到一些结果,如果您以前安装了nodejs版本,否则您可以继续阅读.

我以前的0.10.3 nodejs版本有uv.h到node-gyp一些喜欢

<DRIVERLETTER>:\Users\<USERNAME>\.node-gyp\0.10.3\deps\uv

所以如果你阅读了npm文档,你会发现npm安装的参数

The –nodedir=/path/to/node/source argument will allow npm to find the
node source code so that npm can compile native modules.

所以最后的命令应该是

npm install <package> --nodedir="<DRIVERLETTER>:\Users\<USERNAME\.node-gyp\0.10.3"

你可能会收到一些警告,但是应该成功完成.

原文链接:https://www.f2er.com/windows/371539.html

猜你在找的Windows相关文章