我在命令行工作相当新。我有一个项目,我已经设置了gulp,并安装了gulp并成功编译了sass文件。但是,我无法通过以下方式安装canvas:
$ npm install canvas
我需要安装canvas,因为必须运行css-sprite的依赖项。我收到以下错误。我安装了cairo,quartz和homebrew。我已经研究过其他门票,并尝试运行export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig
并重新安装。我没有运气,也不知道在尝试进行故障排除时还能做些什么。
这是错误......
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
canvas@1.1.3 install /usr/local/lib/node_modules/canvas
node-gyp rebuild
./util/has_cairo_freetype.sh: line 4: pkg-config: command not found
gyp: Call to './util/has_cairo_freetype.sh' returned exit status 0.
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:337:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Darwin 13.1.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/canvas
gyp ERR! node -v v0.10.26
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm ERR! canvas@1.1.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the canvas@1.1.3 install script.
npm ERR! This is most likely a problem with the canvas package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls canvas
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 13.1.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "canvas"
npm ERR! cwd /Users/kylebebeau/websites/ls/code/templates/ls3
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/kylebebeau/websites/ls/code/templates/ls3/npm-debug.log
npm ERR! not ok code 0
非常感谢任何帮助或指导。
答案 0 :(得分:2)
我也有这个问题。我还用brew来安装cairo和quartz。我遵循了这些说明here,最具体地说,这一步解决了我的问题。
export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig
如果您希望它在会话期间保持不变,请务必将其添加到.bashrc
或.zshrc
。成功编译后我删除了node_modules
目录,并在新的终端会话中再次尝试npm install
,我不得不重新导出PKG_CONFIG_PATH以允许它再次正确编译。
这是我的输出缩写为演示。
$ npm install
> node-gyp rebuild
Package xcb-shm was not found in the pkg-config search path.
Perhaps you should add the directory containing `xcb-shm.pc'
to the PKG_CONFIG_PATH environment variable
Package 'xcb-shm', required by 'cairo', not found
gyp: Call to './util/has_cairo_freetype.sh' returned exit status 0. while trying to load binding.gyp
gyp ERR! configure error
...
$ export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig
$ npm install
$ canvas@1.1.3 install $HOME/projects/canvas/node_modules/canvas
$ node-gyp rebuild
...
Successful Compile
npm start
此时无误地工作
我希望这可以帮助其他任何人遇到这个。