安装 npm --save install canvas 时报错

2018-04-28 09:24:52 +08:00
 yangheng4922

按照 https://github.com/Automattic/node-canvas/wiki/Installation---Windows 这个文档安装好了依赖 安装时还是报错 系统是 win10 的

  PS D:\_Project\text1> npm  --save install canvas

  > canvas@1.6.10 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 text1@1.0.0 No description
  npm WARN text1@1.0.0 No repository field.

  npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! canvas@1.6.10 install: `node-gyp rebuild`
  npm ERR! Exit status 1
  npm ERR!
  npm ERR! Failed at the canvas@1.6.10 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>
4178 次点击
所在节点    程序员
5 条回复
KuroNekoFan
2018-04-28 10:33:20 +08:00
建议你先 npm i -g windows-build-tools。https://www.npmjs.com/package/windows-build-tools,一次性解决 windows 下 node-gyp 带来的烦恼
Sparetire
2018-04-28 11:21:29 +08:00
看起来是没找到 GTK, 建议先确认 VS 2015(及以上)或者楼上提到的 windows-build-tools 是否按照, 再确认 GTK 是否安装, 不过即使都装了, 还是可能会出错...
可以考虑
npm i --save canvas -f
cd node_modules/canvas
node-gyp rebuild --GTK_Root="GTK 目录"
手动编译
yangheng4922
2018-04-28 11:26:08 +08:00
@KuroNekoFan 可以哦 之前都没找到这个命令
使用这个命令可以不用手动安装依赖了么
DevNet
2018-04-28 11:59:49 +08:00
cnpm 据说好用……
mrcn
2018-04-28 13:22:15 +08:00
我之前也遇到了这个问题。

最后无奈选择了 WSL。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/450580

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX