mac 安裝 node.js 的 canvas


安裝指南在這,但是有坑。。

https://github.com/Automattic/node-canvas/wiki/Installation---OSX

1、安裝pkg-config

$ curl http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz -o pkgconfig.tgz
$ tar -zxf pkgconfig.tgz && cd pkg-config-0.28
$ ./configure && make install

問題1:安裝包文件夾別放在名字有空格的文件夾里,讀不出來

問題2:install: /usr/local/bin/pkg-config: Permission denied

   這里不是說用sudo 就行了,是說/usr/local/bin/有問題

   運行 sudo chmod 777 /usr/local/bin/

   ps:

    $ ./configure && make install

   這句話最好分開寫,記得加sudo

    $ ./configure

   這句話沒有用的時候用:

    sudo ./configure --with-internal-glib && make install

然后出現一批make[5]: Nothing to be done for [***]就成功了

2、安裝pixman

   按照他的來

    $ curl http://www.cairographics.org/releases/pixman-0.30.0.tar.gz -o pixman.tar.gz
    $ tar -zxf pixman.tar.gz && cd pixman-0.30.0/
    $ ./configure --prefix=/usr/local --disable-dependency-tracking
    $ make install

    安裝0.30.0,是個坑爹的選擇,出現了clang 編譯錯誤,好像解決就要安裝homebrew,但是仍然完全不知道如何解決。。

    冒險安裝了最新版本0.34.0 問題解決,目前沒有不良反應。。

3、安裝cairo

  $ curl http://cairographics.org/releases/cairo-1.12.18.tar.xz -o cairo.tar.xz
  $ tar -xf cairo.tar.xz && cd cairo-1.12.18
  $ ./configure --prefix=/usr/local --disable-dependency-tracking
  $ make install

   考慮到pixman用的最新版本,這個我也下了最新的cairo-1.14.6

  問題1:configure: error: recommended PNG functions feature could not be enabled

  這個官網上有解決方案:http://ethan.tira-thompson.com/Mac_OS_X_Ports.html 安裝這個庫

  為了保險運行了下面兩句話:

  $ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
  $export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig

   然后sudo make install成功

4、安裝canvas

  到要安裝canvas的文件夾npm ,失敗:

> canvas@1.3.10 install******/node_modules/canvas
> node-gyp rebuild

SOLINK_MODULE(target) Release/canvas-postbuild.node
CXX(target) Release/obj.target/canvas/src/Canvas.o
In file included from ../src/Canvas.cc:20:
../src/JPEGStream.h:10:10: fatal error: 'jpeglib.h' file not found
#include <jpeglib.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/npm/node_modules/node-gyp/lib/build.js:270:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Darwin 15.3.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/fengyujia/Documents/My Code/zc_core/node_modules/canvas
gyp ERR! node -v v5.3.0
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "canvas"
npm ERR! node v5.3.0
npm ERR! npm v3.3.12
npm ERR! code ELIFECYCLE

npm ERR! canvas@1.3.10 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the canvas@1.3.10 install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, 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! Please include the following file with any support request:
npm ERR! ******/npm-debug.log

解決辦法看這:https://github.com/Automattic/node-canvas/issues/225

按着他們的討論一路執行下去,最后的那句

xcode-select --install

有效(不知道前面的命令有沒有影響)

安裝完這個后就可以npm install canvas了

 
        

    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM