node-canvas 安装报错

发布时间 2023-11-19 19:27:34作者: lrs2187

node-canvas 安装报错内容一般如下

....
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-pre-gyp install --fallback-to-build --update-binary
npm ERR! Warning: Missing input files:
npm ERR! C:\GTK\bin\libgmodule-2.0-0.dll
npm ERR! C:\GTK\bin\libpangocairo-1.0-0.dll
npm ERR! C:\GTK\bin\libexpat-1.dll
npm ERR! C:\GTK\bin\zlib1.dll
npm ERR! C:\GTK\bin\libfontconfig-1.dll
npm ERR! C:\GTK\bin\libintl-8.dll
npm ERR! C:\GTK\bin\libpng14-14.dll
npm ERR! C:\GTK\bin\libglib-2.0-0.dll
npm ERR! C:\GTK\bin\libgobject-2.0-0.dll
npm ERR! C:\GTK\bin\libgthread-2.0-0.dll
npm ERR! C:\GTK\bin\libpangowin32-1.0-0.dll
npm ERR! C:\GTK\bin\libcairo-2.dll
npm ERR! C:\GTK\bin\libpango-1.0-0.dll
npm ERR! C:\GTK\bin\libfreetype-6.dll
npm ERR! C:\GTK\bin\libpangoft2-1.0-0.dll
npm ERR!
npm ERR!   Backend.cc
npm ERR! C:\Users\lrsgz\scratch\scratch-paint-develop\node_modules\canvas\src\backend\Backend.h(3,10): fatal  error C1083: �޷��?����ļ�: ��cairo.h��: No such file or directory [C:\Users\lrsgz\scratch\scratch-paint-develop\node_modules\canvas\build\canvas.vcxproj]
npm ERR! Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\lrsgz\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --update-binary --module=C:\Users\lrsgz\scratch\scratch-paint-develop\node_modules\canvas\build\Release\canvas.node --module_name=canvas --module_path=C:\Users\lrsgz\scratch\scratch-paint-develop\node_modules\canvas\build\Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v108' (1)
...

这时,只需下载官方给的windows版 GTK 2(不是 GTK 3)压缩包,

(官方直连) Win32 Win64

123云盘(荐)123云盘(无提取码,长期有效)

然后解压到 C:\GTK 里(不存在GTK文件夹则新建一个再解压进去),就解决了。

123云盘链接挂了在评论区
参考:
https://github.com/Automattic/node-canvas/wiki/Installation:-Windows