I'm trying to get working canvas on node js. I'm using Windows Vista. After basic approach npm install canvas
failed (see error below), I have looked up some tutorials, here is what I have tried:
sources:
installing-node-canvas-for-windows
LearnBoost/node-canvas/wiki/Installation---Windows
log in console (after running npm install canvas
in cmd):
log contains several warnings, I don't thing these are the problem - it is mostly something like 'conversion from double to float', and one error marked in red color:
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]
And at the very end of log there is:
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
After that, nothing appeared in node-module folder (no canvas subdirectory, npm after unsuccessful installation removed the subdirectory).
So I have also tried to download canvas module manually from github, unzip it in node-modules and then run node-gyp configure
in node-modules/canvas with success, and node-gyp build
, which unfortunatelly gave me the same error Cannot open include file: 'cairo.h'
.
I have read everything that I found on this carefully. If you can suggest any help, please do it.
I have managed to get it working on my new Windows 8 machine, so I want to share some details that can be helpful to others.
I am using:
Be sure to have Python 2 and GTK\bin in your path.
I have downloaded files manualy from https://github.com/Automattic/node-canvas and saved it to node_modules/canvas.
Then I run node-gyp configure build
in canvas directory. Errors occured. I had to edit binding.gyp (https://github.com/Automattic/node-canvas/blob/master/binding.gyp) in order to match actual files in GTK folder.
For example:
There can be more, you should be able to read which files are making problems from error log and then edit the names to match files in GTK folder.
After editing binding.gyp, command node-gyp configure build
finished successfuly. Although I am not able to work with some jpg files in Canvas (I have not tested it properly), png files work fine.
It can happen to you, that every node-gyp command fails with message (possibly marked in red) similar to:
"...bcrypt_lib.vcxproj(47,46): error MSB4025: Could not load file project. An invalid character for the specified encoding., Line 47, position 46."
It it most probably because you have special character in the name of your user folder. (The fact, that Windows 8 automatically creates the name of your user folder from your first name is the lamest thing about Win 8).
2 quick solutions:
node-gyp configure build
from that accountHope this helps.