携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第2天,点击查看活动详情
mac 上安装node-canvas问题 node版本v16.14.0
安装canvas命令,项目根目录下:
npm install canvas
如果遇到如下报错问题:
由于是M1 arm系统所以使用arch -arm64重新安装
arch -arm64 brew install pkg-config cairo pango jpeg giflib librsvg
brew install libtiff gdk-pixbuf librsvg
设置环境变量:
CPLUS_INCLUDE_PATH=/opt/homebrew/include yarn
如继续报错
Symbol not found: _cairo_fill
在安装好的node-canvas的 readme 中查看:
If you don't have a supported OS or processor architecture, or you use
--build-from-source, the module will be compiled on your system. This requires several dependencies, including Cairo and Pango.
尝试使用以下命令安装:
yarn add canvas --build-from-source
就可以了。如有遇到其他问题的小伙伴。可以一起讨论。