Package cairo was not found in the pkg-config search path. Node j.s install canvas issue
Asked Answered
K

10

140

I am having a problem installing installing the canvas module in node..It seems to be something with cairo I am getting this error...

npm http GET https://registry.npmjs.org/canvas
npm http 304 https://registry.npmjs.org/canvas
npm http GET https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/nan

> [email protected] install /Users/plimb/Desktop/motion-therapy/node_modules/canvas
> node-gyp rebuild

Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cairo' found
gyp: Call to './util/has_cairo_freetype.sh' returned exit status 0. 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/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:424:16)
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 Darwin 13.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/plimb/Desktop/motion-therapy/node_modules/canvas
gyp ERR! node -v v0.10.21
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm ERR! weird error 1 
npm ERR! not ok code 0

I'm not sure what it all means! Would appreciate any help!For example how to a mkdir cairo pc in the pkg_config_path environment variable?

Kristy answered 28/2, 2014 at 16:12 Comment(2)
See if this helps out: github.com/LearnBoost/node-canvas/issues/225Casey
ah thanks ken, I followed this but now I have this error CXX(target) Release/obj.target/canvas/src/Canvas.o In file included from ../src/Canvas.cc:7: ../src/Canvas.h:19:10: fatal error: 'cairo/cairo.h' file not found #include <cairo/cairo.h>Kristy
C
201

Had the same problem and @Epistemex's link helped me troubleshoot it.

... You need to install libcairo2-dev, libjpeg-dev and libgif-dev packages ...

sudo apt-get install libcairo2-dev libjpeg-dev libgif-dev
Cohabit answered 14/5, 2014 at 8:9 Comment(4)
I also needed the pangocairo package, resolved with sudo apt-get install libpango1.0-devSlightly
This wont work in amzon ec2 instance, as they are not debian? any one know yum command for thisVincent
cairo-devel libjpeg-devel and giflib-devel are the Amazon Linux packages. @VincentLabio
@AdlenAfane comment is really relevant for those wanting install manim.Staub
B
73

I was also facing same issue on mac so I have tried these steps & I got solution

Mac OSX Version >=10.7.5 node -v = v0.8.12

$ brew install cairo
$ pkg-config --atleast-version=1.12.2 cairo
$ echo $?

If it returns a 1 you will need to set the PKG_CONFIG_PATH environment variable so cairo.pc and fontconfig.pc can be found

$ locate cairo.pc
$ export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig/

Running pkg-config again ...

$ pkg-config --atleast-version=1.12.2 cairo

$ echo $?

If it returns a 0 then all is well in the hood.

$ npm install canvas
Bombacaceous answered 30/12, 2014 at 12:58 Comment(3)
Appreciate the details. Good one.Antoineantoinetta
Thanks for the pointers using Mac/brew. On Mac, if you're using macports, this worked for me: $ sudo port install cairo $ sudo port install pkgconfig # not sure this one is mandatory... :/ $ npm install canvasSceptic
What if it continues to return 1 after running export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/?Bottle
I
32

Had the same problem on OS X 10.11.2 while installing qrcode package.

Solved by installing these ones:

brew install cairo
brew install pkg-config
xcode-select --install
Integrity answered 15/1, 2016 at 23:21 Comment(3)
Only brew install cairo was sufficient in my case (macOS Sierra 10.12.1)Sheasheaf
with a brand-new installation of macOS Sierra 10.12 (Recovered), brew install cairo should be enough, just confirmed.Glassblowing
it looks like brew install cairo automatically install pkg-config as wellThermoelectrometer
T
15

If anyone is still having this problem and found this page, the following works for CentOS 6.6:

sudo yum install cairo cairo-devel

Basically the solution is you need to install the development package as well as the regular package (the best answer here does the same thing - except is for Ubuntu - every distro can be different).

Tillman answered 15/4, 2015 at 16:46 Comment(0)
A
9

I followed the steps given by @Piyush. But I needed an extra step to make it work. I'm using OS X 10.14.5

So this is what I followed.

brew install pkg-config
brew install cairo
pkg-config --atleast-version=1.12.2 cairo
export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig/
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/opt/libffi/lib/pkgconfig"
npm install canvas
Anyplace answered 22/5, 2019 at 5:46 Comment(0)
T
6

For Ubuntu, these're the commands. Also, here's the reference.

$ sudo apt-get update 
$ sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev 
Taxiway answered 26/4, 2020 at 14:38 Comment(0)
E
5

Try this on mac:

brew install pkg-config cairo pango libpng jpeg giflib
Expect answered 9/2, 2022 at 5:13 Comment(1)
This worked for me! Thanks! Running a m2 macbook air with OSX 12.6, node v18.12.1, and npm 8.19.3Unclad
J
4

The accepted answer is just fine if you use apt-get. For YUM/DNF users (Fedora, CentOS, other RHEL-like systems), use the following

yum install cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel
Janessa answered 10/10, 2018 at 20:15 Comment(0)
D
2

When I ran into this problem the issue was that the version of pkg-config on my path was the version supplied by chefdk instead of the homebrew installed version.

$ which pkg-config
/usr/local/bin/pkg-config

$ eval "$(chef shell-init bash)"
$ which pkg-config
/opt/chefdk/embedded/bin/pkg-config

The solution was to remove the eval "$(chef shell-init bash)" entry from my bash profile.

More discussion of the issue in chefdk's path generation on Github https://github.com/chef/chef-dk/issues/313

Desmonddesmoulins answered 1/2, 2018 at 0:7 Comment(0)
A
1

I just needed to install pkg-config on OSX 10.10.4

brew install pkg-config

Amelia answered 18/9, 2015 at 6:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.