Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install Canvas on a Raspberry pi

Hello I want to install canvas for a discord.js Bot. When I try to install canvas with following command

npm install canvas

I get following error:

pi@server:~/Bots/Discord/Java $ npm install canvas

> [email protected] install /home/pi/Bots/Discord/Java/node_modules/canvas
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download 
node-pre-gyp WARN Tried to download(404): https://github.com/node-gfx/node-canvas-prebuilt/releases/download/v2.6.1/canvas-v2.6.1-node-v72-linux-glibc-arm.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v72 ABI, glibc) (falling back to source compile with node-gyp) 
Package pixman-1 was not found in the pkg-config search path.      
 Perhaps you should add the directory containing `pixman-1.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'pixman-1' found
    gyp: Call to 'pkg-config pixman-1 --libs' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
    gyp ERR! configure error 
    gyp ERR! stack Error: `gyp` failed with exit code: 1
    gyp ERR! stack     at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
    gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    gyp ERR! System Linux 5.4.51-v7+
    gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/home/pi/Bots/Discord/Java/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/home/pi/Bots/Discord/Java/node_modules/canvas/build/Release" "--napi_version=6" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v72"
    gyp ERR! cwd /home/pi/Bots/Discord/Java/node_modules/canvas
    gyp ERR! node -v v12.18.4
    gyp ERR! node-gyp -v v5.1.0
    gyp ERR! not ok 
    node-pre-gyp ERR! build error 
    node-pre-gyp ERR! stack Error: Failed to execute '/usr/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/pi/Bots/Discord/Java/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/home/pi/Bots/Discord/Java/node_modules/canvas/build/Release --napi_version=6 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
    node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/pi/Bots/Discord/Java/node_modules/canvas/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
    node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
    node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
    node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
    node-pre-gyp ERR! System Linux 5.4.51-v7+
    node-pre-gyp ERR! command "/usr/bin/node" "/home/pi/Bots/Discord/Java/node_modules/canvas/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
    node-pre-gyp ERR! cwd /home/pi/Bots/Discord/Java/node_modules/canvas
    node-pre-gyp ERR! node -v v12.18.4
    node-pre-gyp ERR! node-pre-gyp -v v0.11.0
    node-pre-gyp ERR! not ok 
    Failed to execute '/usr/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/pi/Bots/Discord/Java/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/home/pi/Bots/Discord/Java/node_modules/canvas/build/Release --napi_version=6 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
    npm WARN [email protected] No description
    npm WARN [email protected] No repository field.
    
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the [email protected] install script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/pi/.npm/_logs/2020-10-03T09_17_54_892Z-debug.log

Someone know why I get this error? I use Node 12.18.4 on a Raspberry pi 3B

Thanks for answer Tjum28 :)

like image 976
Tjum28 Avatar asked Oct 03 '20 09:10

Tjum28


People also ask

Can you use canvas in node?

createCanvas() Creates a Canvas instance. This method works in both Node. js and Web browsers, where there is no Canvas constructor.

What is canvas in node JS?

The node-canvas package is a NodeJS module allows you to create an image programatically. The package uses Cairo 2D graphics library so that you can generate an image in many common formats like JPG, JPEG or PNG.


1 Answers

According to the node-canvas wiki, You will need to install a few dependencies from apt.

Simply run:

  1. sudo apt-get update
  2. sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev

After installing these canvas will install just fine.

like image 61
Zakhil Avatar answered Oct 18 '22 23:10

Zakhil