运行npm install时出现node-gyp错误

13

我对node不熟悉,在这里有些困惑。在Mac OS X和Centos 6上都遇到了这个错误。我尝试了所有的“npm install xxx”命令,但都出现了这个错误。请问如何解决这个错误?

类似于npm install gives node-gyp error,但我的用户名中没有空格,这也是解决他问题的原因。

npm install canvas

> canvas@1.6.6 install /home/test1/ng2-webpack-demo/node_modules/canvas
> node-gyp rebuild

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/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:336:16)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit 
(internal/child_process.js:215:12)
gyp ERR! System Linux 2.6.32-642.4.2.el6.x86_64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-
gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/test1/ng2-webpack-demo/node_modules/canvas
gyp ERR! node -v v6.11.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN @angular/animations@4.3.6 requires a peer of @angular/core@4.3.6 but 
none was installed.
npm WARN @angular/material@2.0.0-beta.8 requires a peer of @angular/cdk@2.0.0-
beta.8 but none was installed.
npm WARN @angular/material@2.0.0-beta.8 requires a peer of 
@angular/core@^4.0.0 but none was installed.
npm WARN @angular/material@2.0.0-beta.8 requires a peer of 
@angular/common@^4.0.0 but none was installed.
npm WARN @ngtools/webpack@1.2.10 requires a peer of @angular/tsc-
wrapped@^0.5.0 but none was installed.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.2 
(node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for 
fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: 
{"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! canvas@1.6.6 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the canvas@1.6.6 install script.
npm ERR! This is probably not a problem with npm. There is likely additional 
logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/test1/.npm/_logs/2017-08-29T15_54_58_848Z-debug.log

对于那些遇到这个问题的人,我解决的方法是切换到CentOS 7,并运行rpm -ivh https://kojipkgs.fedoraproject.org//packages/http-parser/2.7.1/3.el7/x86_64/http-parser-2.7.1-3.el7.x86_64.rpm && yum -y install nodejs,参考链接:https://bugs.centos.org/view.php?id=13669&nbn=1。 - mba12
请查看此链接:https://dev59.com/c1cP5IYBdhLWcg3wf6Cb - mohammad javad ahmadi
这篇文章中的评论似乎都没有解释为什么对我而言它是间歇性的。在同一台机器上重新运行完全相同的构建,结果就好了。 - Dylan Nicholson
你可以尝试这样安装:brew install pkg-config cairo pango libpng jpeg giflib librsvg - undefined
2个回答

10

这是一个已知的画布问题,可能是因为缺少本地库所致。
尝试以下操作看看是否有帮助:

sudo npm uninstall -g node-gyp
sudo npm install -g node-gyp
brew install pkg-config cairo libpng jpeg giflib
npm i canvas

来源:https://github.com/Automattic/node-canvas/issues/913#issuecomment-368042394

这篇文章讨论了在使用node-canvas时,发生“Could not load canvas”的错误。原因是缺少依赖库libgif-dev和libjpeg-dev,需要安装这些依赖库才能正常运行。如果您遇到了类似的问题,请先检查是否已安装这些依赖库。

3
在Ubuntu上安装软件包cairo时,出现“找不到软件包'cairo'”的错误提示。 - k102
如果我问一下,你用brew安装了哪些包呢?pkg-config cairo libpng jpeg giflib - notacorn
我相信那些只是Canvas的本地依赖项。 - Shan

3

我遇到了同样的错误,原因是我没有安装clang编译器。 我的解决方法是安装build-essential包。

sudo apt-get install build-essential

我正在使用Ubuntu 20.1版本。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接