npm i canvas 报错信息
$ npm i canvas
> canvas@1.6.13 install /Users/jayson/Documents/workspace/xuebang/question-bank-front_uat_20181026/node_modules/canvas
> node-gyp rebuild
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
./util/has_lib.sh: line 31: pkg-config: command not found
gyp: Call to './util/has_lib.sh freetype' returned exit status 0 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/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:345:16)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 16.7.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/jayson/Documents/workspace/xuebang/question-bank-front_uat_20181026/node_modules/canvas
gyp ERR! node -v v10.14.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: canvas@1.6.13 (node_modules/canvas):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: canvas@1.6.13 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
up to date in 9.553s
复制代码
brew install pkg-config
注意到:pkg-config: command not found
这个报错,是说操作系统上少了这个命令。参考Can't install rmagick, pkg-config: command not found这篇文章。(对于macos系统来说),主要是执行一下命令:
brew uninstall pkg-config
brew install pkg-config
brew unlink pkg-config && brew link pkg-config
复制代码
详细执行过程记录:
$ brew install pkg-config
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
arangodb awscli binaryen ompl scala
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.2.sierra.bottle.tar.gz
Already downloaded: /Users/jayson/Library/Caches/Homebrew/downloads/c66b3ea1aa568233b601c4df3026803081d97cc5f1e11f92a1b3c04588e45678--pkg-config-0.29.2.sierra.bottle.tar.gz
==> Pouring pkg-config-0.29.2.sierra.bottle.tar.gz
? /usr/local/Cellar/pkg-config/0.29.2: 11 files, 627.1KB
复制代码
记得把pkg-config的路径添加到.bash_profile到path中:
export PKG_CONFIG_PATH = /usr/local/Cellar/pkg-config/0.29.2/
export PATH=$PKG_CONFIG_PATH/bin:$PATH
复制代码
再尝试 npm i canvas 报错信息
这次报以下错误:
$ npm i canvas
> canvas@1.6.13 install /Users/jayson/Documents/workspace/xuebang/question-bank-front_uat_20181026/node_modules/canvas
> node-gyp rebuild
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
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
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:345:16)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 16.7.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/jayson/Documents/workspace/xuebang/question-bank-front_uat_20181026/node_modules/canvas
gyp ERR! node -v v10.14.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: canvas@1.6.13 (node_modules/canvas):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: canvas@1.6.13 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
up to date in 9.059s
复制代码
brew install cairo
参考这篇文章npm install canvas简明指南 注意到:to the PKG_CONFIG_PATH environment varia