347 文字
2 分
Q. yarn upgradeするとcanvas: Command failedと言われ失敗するようになった
次のようなエラーが出ていた。エラーをよく見ると、事前にビルドされた node-canvas のバイナリの取得に失敗したため、手元でビルドするようにフォールバックしたが、ビルドにも失敗していることが分かる。
> yarn upgrade react -latest[1/3] ⠠ canvas[-/3] ⠠ waiting...warning Error running install script for optional dependency: "/Users/.../node_modules/canvas: Command failed.Exit code: 1Command: node-pre-gyp install --fallback-to-build --update-binary...Output:node-pre-gyp info it worked if it ends with oknode-pre-gyp info using [email protected]node-pre-gyp info using [email protected] | darwin | arm64node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v108-darwin-unknown-arm64.tar.gznode-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v108-darwin-unknown-arm64.tar.gznode-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v108 ABI, unknown) (falling back to source compile with node-gyp)node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v108-darwin-unknown-arm64.tar.gz...node-pre-gyp ERR! build errornode-pre-gyp ERR! stack Error: Failed to execute '/Users/.../node/Users/.../node-gyp.js configure --fallback-to-build --update-binary--module=/Users/.../canvas/build/Release/canvas.node --module_name=canvas--module_path=/Users/.../canvas/build/Release --napi_version=9--node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v108' (1)
node-canvas とは、Web Canvas API 互換な API を Node.js で利用するされる npm パッケージで、jsdom など様々なライブラリで利用されている。これはネイティブモジュールに依存しており、
自己完結型のバイナリが配布されているが、darwin-arm64 環境のものは不可能らしく配布されていないため、手元でビルドして上げる必要がある。
https://github.com/Automattic/node-canvas/issues/2036
node-canvas の README にあるコマンドを実行して、手元でコンパイルできるようにする。
今回の環境は macOS であったため、次のコマンドを実行して解決した。
brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling
Q. yarn upgradeするとcanvas: Command failedと言われ失敗するようになった
https://blog.ohirunewani.com/posts/yarn-upgrade-canvas-command-failed/