Make the node-gyp rebuild command work on Mac Os

Ing. Alejandro Villalón
Villalon Engineering
3 min readSep 20, 2019

--

Hi fellow programmer, I was trying to install a node package on my Mac Os (High Sierra) that needs to execute the node-gyp rebuild command:

npm install esc-pos-encoder-ionic --save

I got the following error:

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_lib.sh freetype’ returned exit status 0 while in binding.gyp. while trying to load binding.gyp

That stagnant my work, and I had to waste time researching the solution, so I share how to fix the error so that you can solve it quickly and continue your development without delay.

The problem is that the runtime environment does not find the package cairo inside the search path of the pkg-config, so we need to export the package cairo in the search path of the pkg-config.

The first thing I needed was to install Homebrew. One that I installed it, I used it to help me install the cairo and pkg-config packages, I did that with the following commands:

brew install cairo
brew install pkg-config

Doing that I got the packages that I need on my pc. Now what we have to do is find the file cairo.pc, we do that with the command:

locate cairo.pc

I got the following values:

/usr/local/Cellar/cairo/1.16.0_2/lib/pkgconfig/cairo.pc
/usr/local/lib/pkgconfig/cairo.pc

If you open the file /usr/local/lib/pkgconfig/cairo.pc you realize that it refers to the file /usr/local/Cellar/cairo/1.16.0_2/lib/pkgconfig/cairo.pc, so it is only necessary export the file reference /usr/local/lib/pkgconfig/cairo.pc to the pkg config path, we do that with the following command:

export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig"

As you can see, it refers to the container folder of the cairo.pc file, not the file.

A gift tip

The folder /usr/local/opt/contains a shortcut to each package installed on your system.

For example, now I get the error:

Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc’
to the PKG_CONFIG_PATH environment variable
Package ‘libffi’, required by ‘gobject-2.0’, not found
gyp: Call to ‘./util/has_lib.sh freetype’ returned exit status 0 while in binding.gyp. while trying to load binding.gyp

So another quick way to find the file that I need to export is by using the shortcut of the libffi package that is inside /usr/local/opt/. Additionally, I need to find the .pc file that is inside /lib/pkgconfig/.

So the command to import the libffi package into the search path environment of the pkg-config is as follows:

export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/opt/libffi/lib/pkgconfig"

Now, if I test with the same command:

npm install esc-pos-encoder-ionic --save

Great, it works! The fact that warnings appear means that the script was executed correctly.

../src/CanvasRenderingContext2d.cc:998:21: warning: ‘NumberValue’ is deprecated [-Wdeprecated-declarations]
dw = info[3]->NumberValue();
^
/Users/IngAjVillalon/Library/Caches/node-gyp/10.15.3/include/node/v8.h:2475:3: note: ‘NumberValue’ has been explicitly marked deprecated here
V8_DEPRECATED(“Use maybe version”, double NumberValue() const);
^
/Users/IngAjVillalon/Library/Caches/node-gyp/10.15.3/include/node/v8config.h:327:29: note: expanded from macro ‘V8_DEPRECATED’
declarator __attribute__((deprecated))

Warnings only mean that some properties or functions that the current package is using have been discontinued, which for now work but in the future, they will not. But it doesn’t mean there are mistakes.

So fellows, the key commands to install node packages that use the node-gyp rebuild command are:

export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig"export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/opt/libffi/lib/pkgconfig"

I hope this post has served you and I have contributed something to the community with it. If you liked this post and found it helpful! Give me some claps!

Did the article help you?

Buy me a coffee in thanks, to motivate me to continue sharing articles.

Buy me a coffee in thanks, to motivate me to continue sharing articles.

--

--

Ing. Alejandro Villalón
Villalon Engineering

Computer engineer specializing in the App Development process. Founder of Villalón Engineering, a community where ideas materialize.