3

我在nodejs wiki之后安装nodejs,一切顺利,然后按照这种方式安装node canvas https://github.com/LearnBoost/node-canvas/wiki/Installation---OSX,“$ npm install canvas”之前的步骤进展顺利,但最后一步“$ npm install canvas”一次又一次失败,我尝试安装Nodejs构建和安装,我也尝试了“sudo”,我尝试了“$ export PKG_CONFIG_PATH=.. ...”,但仍然无法安装画布,我确信我已经清楚地遵循了所有指南。以下是日志:

SLMacs-MacBook-Pro-2:~ percy$ npm install canvas
npm http GET https://registry.npmjs.org/canvas
npm http 304 https://registry.npmjs.org/canvas

> canvas@1.0.3 install /Users/macbookpro/node_modules/canvas
> node-gyp rebuild

  CXX(target) Release/obj.target/canvas/src/Canvas.o
In file included from ../src/Canvas.cc:7:
../src/Canvas.h:11:10: fatal error: 'v8.h' file not found
#include <v8.h>
         ^
1 error generated.
make: *** [Release/obj.target/canvas/src/Canvas.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:96:17)
gyp ERR! stack     at Process._handle.onexit (child_process.js:678:10)
gyp ERR! System Darwin 12.4.0
gyp ERR! command "node" "/usr/local/bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/macbookpro/node_modules/canvas
gyp ERR! node -v v0.8.12
gyp ERR! node-gyp -v v0.10.6
gyp ERR! not ok 
npm ERR! canvas@1.0.3 install: `node-gyp rebuild`
npm ERR! `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR! 
npm ERR! Failed at the canvas@1.0.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 12.4.0
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "canvas"
npm ERR! cwd /Users/macbookpro
npm ERR! node -v v0.8.12
npm ERR! npm -v 1.1.63
npm ERR! code ELIFECYCLE
npm ERR! Error: EACCES, open 'npm-debug.log'
npm ERR!  { [Error: EACCES, open 'npm-debug.log'] errno: 3, code: 'EACCES', path: 'npm-debug.log' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.4.0
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "canvas"
npm ERR! cwd /Users/macbookpro
npm ERR! node -v v0.8.12
npm ERR! npm -v 1.1.63
npm ERR! path npm-debug.log
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open 'npm-debug.log'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/macbookpro/npm-debug.log
npm ERR! not ok code 0
4

2 回答 2

2

我自己也遇到了这个问题。您可能需要安装一些依赖项。尝试在终端中运行以下命令。

brew install pkg-config cairo pango libpng jpeg giflib librsvg

之后,重新运行 npm install。这对我有用。

于 2021-05-19T18:10:43.200 回答
1

要解决这个问题:

  1. 从http://nodejs.org/dist/v0.10.13/node-v0.10.13.tar.gz下载node 0.10.13的源码
  2. 通过 tar -xvz node-v0.10.13.tar.gz 提取此文件
  3. 将“deps”、“src”和“tools”文件夹复制到“~/.node-gyp/0.10.13”

然后再次运行“npm install canvas”。

我不知道为什么 MacOS 节点包(仅适用于 v0.10.13)缺少这些东西。

于 2013-07-18T10:22:39.953 回答