我正在尝试在Node.js上使用canvas,我使用的是Windows Vista。在基本方法npm install canvas
失败后(请参见下面的错误),我查阅了一些教程,以下是我尝试过的内容:
来源:
installing-node-canvas-for-windows
LearnBoost/node-canvas/wiki/Installation---Windows
- 我安装了旧版Python(2.7.5)并将其添加到了PATH中(并从PATH中移除了Python 3.2)
- 我检查了是否已安装Microsoft Visual Studio 2010专业版
- 我从http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip下载了“all in one” GTK软件包,在C:\GTK\中解压缩,并将“C:\GTK\bin”添加到了PATH
控制台日志(在cmd中运行npm install canvas
后):
日志包含几个警告,我不认为这些是问题 - 大多数是类似于“从double转换为float”,还有一个用红色标记的错误:
init.cc
d:\pathToApp\node_modules\canvas\src\PNG.h(5): fatal error C1083: Cannot
open include file: 'cairo.h': No such file or directory [d:\pathToApp\n
ode_modules\canvas\build\canvas.vcxproj]
在日志的最后,有如下内容:
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:\Program Files\nodejs\node_modules\
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.0.6002
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modu
les\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd d:\pathToApp\node_modules\canvas
gyp ERR! node -v v0.10.16
gyp ERR! node-gyp -v v0.10.9
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0
之后在node-module文件夹中没有出现任何内容(没有canvas子目录,npm在安装失败后删除了子目录)。
所以我尝试手动从Github下载canvas模块,将其解压缩到node-modules中,然后在node-modules/canvas中运行node-gyp configure
,成功后运行node-gyp build
,但不幸的是仍然出现相同的错误Cannot open include file: 'cairo.h'
。
我已经仔细阅读了所有相关资料。如果您有任何建议,请告诉我。