无法安装画布 - NodeJS

分享于2022年11月15日 canvas javascript node.js npm typescript 问答
【问题标题】:Unable to install Canvas - NodeJS无法安装画布 - NodeJS
【发布时间】:2022-11-08 11:41:37
【问题描述】:

当我运行 npm install canvas 并尝试像这样使用它时出现错误: const canvas = require('canvas')

npm ERR! code 1
npm ERR! path C:\Users\josep\OneDrive\Desktop\Bots\Foundation\node_modules\canvas
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-pre-gyp install --fallback-to-build --update-binary
npm ERR! Failed to execute 'C:\Program Files (x86)\nodejs\node.exe C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --update-binary --module=C:\Users\josep\OneDrive\Desktop\Bots\Foundation\node_modules\canvas\build\Release\canvas.node --module_name=canvas --module_path=C:\Users\josep\OneDrive\Desktop\Bots\Foundation\node_modules\canvas\build\Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93 --python=C:\Users\josep\.windows-build-tools\python27\python.exe --msvs_version=2015' (1)
npm ERR! node-pre-gyp info it worked if it ends with ok
npm ERR! node-pre-gyp info using node-pre-gyp@1.0.9
npm ERR! node-pre-gyp info using node@16.15.0 | win32 | ia32
npm ERR! node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.9.3/canvas-v2.9.3-node-v93-win32-unknown-ia32.tar.gz
npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.9.3/canvas-v2.9.3-node-v93-win32-unknown-ia32.tar.gz
npm ERR! node-pre-gyp WARN Pre-built binaries not installable for canvas@2.9.3 and node@16.15.0 (node-v93 ABI, unknown) (falling back to source compile with node-gyp)
npm ERR! node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.9.3/canvas-v2.9.3-node-v93-win32-unknown-ia32.tar.gz
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.0.0
npm ERR! gyp info using node@16.15.0 | win32 | ia32
npm ERR! gyp info ok
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.0.0
npm ERR! gyp info using node@16.15.0 | win32 | ia32
npm ERR! gyp info find Python using Python version 3.10.5 found at "C:\Users\josep\AppData\Local\Programs\Python\Python310\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version was set from command line or npm config
npm ERR! gyp ERR! find VS - looking for Visual Studio version 2015
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS checking VS2022 (17.2.32616.157) found at:
npm ERR! gyp ERR! find VS "C:\Program Files\Microsoft Visual Studio\2022\Community"
npm ERR! gyp ERR! find VS - found "Visual Studio C++ core features"
npm ERR! gyp ERR! find VS - found VC++ toolset: v143
npm ERR! gyp ERR! find VS - found Windows SDK: 10.0.19041.0
npm ERR! gyp ERR! find VS - msvs_version does not match this version
npm ERR! gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS valid versions for msvs_version:
npm ERR! gyp ERR! find VS - "2022"
npm ERR! gyp ERR! find VS - "C:\Program Files\Microsoft Visual Studio\2022\Community"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack     at VisualStudioFinder.fail (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:122:47)
npm ERR! gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:75:16
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:363:14)
npm ERR! gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:71:14
npm ERR! gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:384:16
npm ERR! gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
npm ERR! gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:406:5)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16)
npm ERR! gyp ERR! System Windows_NT 10.0.22000
npm ERR! gyp ERR! command "C:\\Program Files (x86)\\nodejs\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--fallback-to-build" "--update-binary" "--module=C:\\Users\\josep\\OneDrive\\Desktop\\Bots\\Foundation\\node_modules\\canvas\\build\\Release\\canvas.node" "--module_name=canvas" "--module_path=C:\\Users\\josep\\OneDrive\\Desktop\\Bots\\Foundation\\node_modules\\canvas\\build\\Release" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v93" "--python=C:\\Users\\josep\\.windows-build-tools\\python27\\python.exe" "--msvs_version=2015" 
npm ERR! gyp ERR! cwd C:\Users\josep\OneDrive\Desktop\Bots\Foundation\node_modules\canvas
npm ERR! gyp ERR! node -v v16.15.0
npm ERR! gyp ERR! node-gyp -v v9.0.0
npm ERR! gyp ERR! not ok
npm ERR! node-pre-gyp ERR! build error
npm ERR! node-pre-gyp ERR! stack Error: Failed to execute 'C:\Program Files (x86)\nodejs\node.exe C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --update-binary --module=C:\Users\josep\OneDrive\Desktop\Bots\Foundation\node_modules\canvas\build\Release\canvas.node --module_name=canvas --module_path=C:\Users\josep\OneDrive\Desktop\Bots\Foundation\node_modules\canvas\build\Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93 --python=C:\Users\josep\.windows-build-tools\python27\python.exe --msvs_version=2015' (1)
npm ERR! node-pre-gyp ERR! stack     at ChildProcess. (C:\Users\josep\OneDrive\Desktop\Bots\Foundation\node_modules\@mapbox\node-pre-gyp\lib\util\compile.js:89:23)
npm ERR! node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
npm ERR! node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16)
npm ERR! node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
npm ERR! node-pre-gyp ERR! System Windows_NT 10.0.22000
npm ERR! node-pre-gyp ERR! command "C:\\Program Files (x86)\\nodejs\\node.exe" "C:\\Users\\josep\\OneDrive\\Desktop\\Bots\\Foundation\\node_modules\\@mapbox\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build" "--update-binary"
npm ERR! node-pre-gyp ERR! cwd C:\Users\josep\OneDrive\Desktop\Bots\Foundation\node_modules\canvas
npm ERR! node-pre-gyp ERR! node -v v16.15.0
npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.9
npm ERR! node-pre-gyp ERR! not ok
 
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\josep\AppData\Local\npm-cache\_logs\2022-07-12T17_23_56_341Z-debug-0.log
PS C:\Users\josep\OneDrive\Desktop\Bots\Foundation> 

我已经安装了 GTK 和其他东西,但是当我尝试安装 Canvas 时收到此错误。

  • 抱歉,刚刚发现不是图片。错误消息应该在您的问题中。我们不必通过链接来理解您的问题。
  • 发帖时间过长
  • 它不是!错误应该在这里,我在这里为您添加了它..
  • 错误内容如下: You need to install the latest version of Visual Studio including the "Desktop development with C++" workload. For more information consult the documentation at: https://github.com/nodejs/node-gyp#on-windows
  • 404 Not Found 检查版本: github.com/Automattic/node-canvas/releases 看起来没有任何 ...ia32.tar.gz 似乎只支持 x64

【解决方案1】:

在乞求时,我的节点版本是16.10.0,我使用nvm将版本更改为14.10.0后,问题解决了。 如果没有,您可以结帐 https://github.com/Automattic/node-canvas/issues/1733

【讨论】: