Nodejs 安装 npm --save install canvas 时报错,求解答
Nodejs 安装 npm --save install canvas 时报错,求解答
按照 https://github.com/Automattic/node-canvas/wiki/Installation—Windows 这个文档安装好了依赖 安装时还是报错
PS D:\_Project\text1> npm --save install canvas
> [email protected] install D:\_Project\text1\node_modules\canvas
> node-gyp rebuild
D:\_Project\text1\node_modules\canvas>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )
else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Warning: Missing input files:
C:\GTK\bin\libfreetype-6.dll
在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m ”开关。
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.Cpp.InvalidPlatform.Targets(23,7): error MSB8007: The Platform for project 'canvas.vcxproj' is invalid. Platform='x64'. You may be seeing this message becau
se you are trying to build a project without a solution file, and have specified a non-default Platform that doesn't exist for this project. [D:\_Project\text1\node_modules\canvas\build\canvas.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.14393
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\_Project\text1\node_modules\canvas
gyp ERR! node -v v8.11.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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! C:\Users\yangheng\AppData\Roaming\npm-cache\_logs\2018-04-27T09_45_16_307Z-debug.log
PS D:\_Project\text1>
1 回复
在Node.js中安装canvas
模块时遇到错误,通常是因为canvas
模块依赖于一些底层的系统库,这些库需要手动安装或配置。canvas
模块使用Cairo
图形库进行绘图,因此在安装前需要确保你的系统上已经安装了Cairo
及其开发文件。
以下是一些可能的解决步骤,根据你的操作系统不同,步骤会有所区别:
对于Ubuntu/Debian系统:
- 安装必要的依赖:
sudo apt-get install libcairo2-dev pkg-config libjpeg-dev libpng-dev
- 重新安装
canvas
模块:npm install canvas --save
对于macOS:
- 安装
Cairo
和必要的依赖,可以使用Homebrew:brew install cairo pkg-config jpeg libpng
- 同样地,重新安装
canvas
模块:npm install canvas --save
对于Windows:
Windows上安装canvas
可能会更复杂,因为需要手动配置很多依赖。推荐使用Windows Subsystem for Linux (WSL)或者在Windows上运行一个Linux虚拟机来简化安装过程。
如果上述步骤仍然无法解决问题,建议查看npm安装时的错误日志,查找具体的错误信息,可能是缺少其他依赖或者权限问题。错误日志通常会指出缺少哪个库文件或者哪个命令失败。
希望这些步骤能帮助你解决问题!如果还有其他问题,欢迎继续提问。