In a completely empty directory on MacOS High Sierra, yarn add vega gives this warning:
warning Error running install script for optional dependency: "/Users/tom/code/blub/node_modules/canvas: Command failed.\nExit code: 1\nCommand: node-gyp rebuild\nArguments: \nDirectory: /Users/tom/code/blub/node_modules/canvas\nOutput:\ngyp info it worked if it ends with ok\ngyp info using [email protected]\ngyp info using [email protected] | darwin | x64\ngyp info spawn /usr/bin/python\ngyp info spawn args [ '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',\ngyp info spawn args 'binding.gyp',\ngyp info spawn args '-f',\ngyp info spawn args 'make',\ngyp info spawn args '-I',\ngyp info spawn args '/Users/tom/code/blub/node_modules/canvas/build/config.gypi',\ngyp info spawn args '-I',\ngyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',\ngyp info spawn args '-I',\ngyp info spawn args '/Users/tom/.node-gyp/8.9.4/include/node/common.gypi',\ngyp info spawn args '-Dlibrary=shared_library',\ngyp info spawn args '-Dvisibility=default',\ngyp info spawn args '-Dnode_root_dir=/Users/tom/.node-gyp/8.9.4',\ngyp info spawn args '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',\ngyp info spawn args '-Dnode_lib_file=/Users/tom/.node-gyp/8.9.4/<(target_arch)/node.lib',\ngyp info spawn args '-Dmodule_root_dir=/Users/tom/code/blub/node_modules/canvas',\ngyp info spawn args '-Dnode_engine=v8',\ngyp info spawn args '--depth=.',\ngyp info spawn args '--no-parallel',\ngyp info spawn args '--generator-output',\ngyp info spawn args 'build',\ngyp info spawn args '-Goutput_dir=.' ]\nPackage cairo was not found in the pkg-config search path.\nPerhaps you should add the directory containing
cairo.pc'\nto the PKG_CONFIG_PATH environment variable\nNo package 'cairo' found\ngyp: Call to './util/has_lib.sh freetype' returned exit status 0 while in binding.gyp. while trying to load binding.gyp\ngyp ERR! configure error \ngyp ERR! stack Error:gyp` failed with exit code: 1\ngyp ERR! stack at ChildProcess.onCpExit (/usr/lo
Related: #1073
Unfortunately there can be inconsistencies between yarn and npm when performing compilation tasks. See #1045 for more. Echoing my comment there, this looks like a known problem with yarn and node-gyp (https://github.com/yarnpkg/yarn/issues/3728).
One possible fix: Run npm install -g node-gyp then retry yarn.
Another "fix" is to brew install pkg-config cairo libpng jpeg giflib, but anything that requires adding unmanaged / global dependencies isn't really ideal.
Most helpful comment
Another "fix" is to
brew install pkg-config cairo libpng jpeg giflib, but anything that requires adding unmanaged / global dependencies isn't really ideal.