/

如何在 macOS 上解決安裝 Node `canvas` 的問題

如何在 macOS 上解決安裝 Node canvas 的問題

我想使用Node.js的canvas NPM包,但是執行npm install canvas會出現以下錯誤訊息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
npm ERR! code 1
npm ERR! path /Users/flaviocopes/dev/old/generate-images-posts/node\_modules/canvas
npm ERR! command failed
npm ERR! command sh -c node-pre-gyp install --fallback-to-build
npm ERR! Failed to execute '/opt/homebrew/Cellar/[[email protected]](/cdn-cgi/l/email-protection)/16.14.2/bin/node /opt/homebrew/Cellar/[[email protected]](/cdn-cgi/l/email-protection)/16.14.2/lib/node\_modules/npm/node\_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/flaviocopes/dev/old/generate-images-posts/node\_modules/canvas/build/Release/canvas.node --module\_name=canvas --module\_path=/Users/flaviocopes/dev/old/generate-images-posts/node\_modules/canvas/build/Release --napi\_version=8 --node\_abi\_napi=napi --napi\_build\_version=0 --node\_napi\_label=node-v93' (1)
npm ERR! node-pre-gyp info it worked if it ends with ok
npm ERR! node-pre-gyp info using [[email protected]](/cdn-cgi/l/email-protection)
npm ERR! node-pre-gyp info using [[email protected]](/cdn-cgi/l/email-protection) | darwin | arm64
npm ERR! node-pre-gyp WARN Using request for node-pre-gyp https download
npm ERR! node-pre-gyp info check checked for "/Users/flaviocopes/dev/old/generate-images-posts/node\_modules/canvas/build/Release/canvas.node" (not found)
npm ERR! node-pre-gyp http GET https://github.com/node-gfx/node-canvas-prebuilt/releases/download/v2.6.1/canvas-v2.6.1-node-v93-darwin-unknown-arm64.tar.gz
npm ERR! node-pre-gyp http 404 https://github.com/node-gfx/node-canvas-prebuilt/releases/download/v2.6.1/canvas-v2.6.1-node-v93-darwin-unknown-arm64.tar.gz
npm ERR! node-pre-gyp WARN Tried to download(404): https://github.com/node-gfx/node-canvas-prebuilt/releases/download/v2.6.1/canvas-v2.6.1-node-v93-darwin-unknown-arm64.tar.gz
npm ERR! node-pre-gyp WARN Pre-built binaries not found for [[email protected]](/cdn-cgi/l/email-protection) and [[email protected]](/cdn-cgi/l/email-protection) (node-v93 ABI, unknown) (falling back to source compile with node-gyp)
npm ERR! node-pre-gyp http 404 status code downloading tarball https://github.com/node-gfx/node-canvas-prebuilt/releases/download/v2.6.1/canvas-v2.6.1-node-v93-darwin-unknown-arm64.tar.gz
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [[email protected]](/cdn-cgi/l/email-protection)
npm ERR! gyp info using [[email protected]](/cdn-cgi/l/email-protection) | darwin | arm64

要解決這個問題,我執行了以下命令:

1
brew install pkg-config cairo pango libpng jpeg giflib librsvg 

然後npm install canvas就能正常工作了!

tags: [“Node.js”, “canvas”, “macOS”, “npm”, “troubleshooting”]