Skip to content

Installation: Windows

Zach Bjornson edited this page Aug 18, 2018 · 10 revisions

Dependencies

Building the node-canvas module requires:

  1. A global installation of node-gyp.
  2. GTK 2
  3. For optional JPEG support (node-canvas 2.0 and later): libjpeg-turbo

Install with Chocolatey

Be aware that according to known Chocolatey issues it is better to use instructions for manual install, provided below

All the dependencies can be installed with Chocolatey, the package manager for Windows.

  1. choco install -y python2 gtk-runtime microsoft-build-tools libjpeg-turbo (may require sudo/Administrator and reboot).
  2. You will need the cairo library which is bundled in GTK. Download the GTK 2 bundle for Win32 or Win64. Unzip the contents in C:\GTK.
  3. Run npm install canvas or yarn add canvas with command line from your project folder.

Install Manually

1. Installing node-gyp

Follow the instructions here: https://github.com/nodejs/node-gyp#on-windows

2. Installing GTK 2

You will need the cairo library which is bundled in GTK. Download the GTK 2 bundle for Win32 or Win64. Unzip the contents in C:\GTK.

Notes:

  • Both GTK and Node.js need either be 64bit or 32bit to compile successfully.
  • Download GTK 2, not GTK 3, which is missing the required libpng. If you get linker errors you've most likely picked the wrong bundle.
  • If you use a different location than C:\GTK, add a GTK_Root argument to npm install or node-gyp rebuild. For example: node-gyp rebuild --GTK_Root=C:\somewhere\GTK.

3. Installing libjpeg-turbo (optional, for JPEG support; node-canvas 2.0 and later)

Download the latest libjpeg-turbo SDK for Visual C++ (currently libjpeg-turbo-1.5.1-vc.exe or libjpeg-turbo-1.5.1-vc64.exe) and install to its default location (C:\libjpeg-turbo if 32bit or C:\libjpeg-turbo64 if 64bit).

Notes:

  • Both libjpeg-turbo and Node.js need either be 64bit or 32bit to compile successfully.
  • If you use a different location, add a jpeg_root argument to npm install or node-gyp rebuild. For example: node-gyp rebuild --jpeg_root=C:\somewhere\libjpeg-turbo.

4. Installing node-canvas

After all dependencies are setup, npm install canvas or yarn add canvas.