详细记录一次npm i canvas报错的解决过程

这篇博客详细记录了在macos系统上安装npm包canvas遇到的pkg-config和cairo缺失问题的解决过程,包括使用brew安装pkg-config和cairo,并修改.bash_profile的路径,最终成功安装canvas。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值