in win install node-canvas

78 阅读1分钟

in win install node-canvas

what does npm do when run npm i canvas

  • Download canvas package in npm repository
  • Execute the install command in canvas's package.json - node-pre-gyp install --fallback-to-build
  • node-pre-gyp Download canvas compiled binaries for macOS, Linux, and Windows, fall back to build from source if pre-built binaries do not exist or are unavailable
  • node-gyp compiled to node module available for current platform

refer: node environment canvas installation slow, installation failure

install node-canvas with china mirror (solution 1)

  • add canvas_binary_host_mirror in .npmrc
  • use registry.npmmirror.com here
canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas
  • install canvas:
# npm i canvas
# pnpm add -D canvas
# pnpm add -D -w canvas
# pnpm remove -D -w canvas

build node-canvas from source in window (solution 2)

  • prepare py27 -- use conda on window sample to install and remove py27: (powershell|git-bash)
conda info -e;
conda create --name py27 python=2.7;
conda activate py27;
conda deactivate py27;
conda remove --name py27 --all;
  • prepare window-build-tools - install with npm i -g window-build-tools
  • prepare window-build-tools - install with choco install -y microsoft-build-tools
  • prepare window-build-tools - install with 'vs_buildtools.exe'
# 1. download vs_buildtools.exe
# https://keqingrong.cn/blog/2021-02-21-build-tools-on-windows/
# This article does not intend to adopt a global installation of the windows-build-tools npm package


# 2. install vs_buildtools.exe
# vs_buildtools.exe --quiet --add Microsoft.VisualStudio.Workload.MSBuildTools --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.Windows10SDK --includeRecommended

vs_buildtools.exe --add Microsoft.VisualStudio.Workload.MSBuildTools --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.Windows10SDK --includeRecommended
  • prepare node-gyp - install with npm i -g node-gyp
  • prepare gtk runtime - install with choco install -y gtk-runtime
  • prepare gkt
# Download the GTK 2 bundle for Win32 or Win64. Unzip the contents in C:\GTK.
# https://ftp.gnome.org/pub/GNOME/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip

# cp -r "/d/download/gtk2" "/c/gtk" # rm -rf "/c/gtk"; cp -r "/d/download/gtk2-32" "/c/gtk"

node-canvas/wiki/Installation:-Windows

  • prepare libjpeg-turbo to support jpg - install with choco install -y libjpeg-turbo --version 1.2.1;
  • install node-canvas with npm i canvas --build-from-source