Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.1k stars 1.16k forks source link

Command failed:node-pre-gyp install --fallback-to-build --update-binary #2186

Open da-du opened 1 year ago

da-du commented 1 year ago

Steps to Reproduce

When I run yarn, the error is as follows:

warning Error running install script for optional dependency: "/Users/XXX/project/saas-statistics/node_modules/canvas: Command failed.
Exit code: 1
Command: node-pre-gyp install --fallback-to-build --update-binary
Arguments: 
Directory: /Users/XXX/project/saas-statistics/node_modules/canvas
Output:
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@1.0.10
node-pre-gyp info using node@16.19.0 | darwin | arm64
node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.0/canvas-v2.11.0-node-v93-darwin-unknown-arm64.tar.gz
node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.0/canvas-v2.11.0-node-v93-darwin-unknown-arm64.tar.gz 
node-pre-gyp WARN Pre-built binaries not installable for canvas@2.11.0 and node@16.19.0 (node-v93 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.0/canvas-v2.11.0-node-v93-darwin-unknown-arm64.tar.gz 
gyp info it worked if it ends with ok
gyp info using node-gyp@9.3.1
gyp info using node@16.19.0 | darwin | arm64
gyp info ok 
gyp info it worked if it ends with ok
gyp info using node-gyp@9.3.1
gyp info using node@16.19.0 | darwin | arm64
gyp info find Python using Python version 3.8.9 found at \"/Library/Developer/CommandLineTools/usr/bin/python3\"
gyp info spawn /Library/Developer/CommandLineTools/usr/bin/python3
gyp info spawn args [
gyp info spawn args   '/Users/XXX/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/XXX/project/saas-statistics/node_modules/canvas/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/XXX/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/XXX/Library/Caches/node-gyp/16.19.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/XXX/Library/Caches/node-gyp/16.19.0',
gyp info spawn args   '-Dnode_gyp_dir=/Users/XXX/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/XXX/Library/Caches/node-gyp/16.19.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/XXX/project/saas-statistics/node_modules/canvas',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
/bin/sh: pkg-config: command not found
gyp: Call to 'pkg-config pixman-1 --libs' returned exit status 127 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/Users/XXX/node_modules/node-gyp/lib/configure.js:325:16)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)
gyp ERR! System Darwin 21.6.0
gyp ERR! command \"/Users/XXX/.nvm/versions/node/v16.19.0/bin/node\" \"/Users/XXX/node_modules/node-gyp/bin/node-gyp.js\" \"configure\" \"--fallback-to-build\" \"--update-binary\" \"--module=/Users/XXX/project/saas-statistics/node_modules/canvas/build/Release/canvas.node\" \"--module_name=canvas\" \"--module_path=/Users/XXX/project/saas-statistics/node_modules/canvas/build/Release\" \"--napi_version=8\" \"--node_abi_napi=napi\" \"--napi_build_version=0\" \"--node_napi_label=node-v93\"
gyp ERR! cwd /Users/XXX/project/saas-statistics/node_modules/canvas
gyp ERR! node -v v16.19.0
gyp ERR! node-gyp -v v9.3.1
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/Users/XXX/.nvm/versions/node/v16.19.0/bin/node /Users/XXX/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/Users/XXX/project/saas-statistics/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/Users/XXX/project/saas-statistics/node_modules/canvas/build/Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/XXX/project/saas-statistics/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1100:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
node-pre-gyp ERR! System Darwin 21.6.0
node-pre-gyp ERR! command \"/Users/XXX/.nvm/versions/node/v16.19.0/bin/node\" \"/Users/XXX/project/saas-statistics/node_modules/canvas/node_modules/.bin/node-pre-gyp\" \"install\" \"--fallback-to-build\" \"--update-binary\"
node-pre-gyp ERR! cwd /Users/XXX/project/saas-statistics/node_modules/canvas
node-pre-gyp ERR! node -v v16.19.0
node-pre-gyp ERR! node-pre-gyp -v v1.0.10
node-pre-gyp ERR! not ok 
Failed to execute '/Users/XXX/.nvm/versions/node/v16.19.0/bin/node /Users/XXX/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/Users/XXX/project/saas-statistics/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/Users/XXX
[5/5] ♻️  Cleaning modules...
success Saved lockfile.
✨  Done in 94.91s.

This is the information for run yarn why canvas

yarn why v1.22.19
warning ../../package.json: No license field
[1/4] 🤔  Why do we have the module "canvas"...?
[2/4] 🚚  Initialising dependency graph...
warning Lockfile has incorrect entry for "antd@3.10.2". Ignoring it.
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "canvas@2.11.0"
info Reasons this module exists
   - "@types#react-pdf#@types#pdfjs-dist#pdfjs-dist" depends on it
   - Hoisted from "@types#react-pdf#@types#pdfjs-dist#pdfjs-dist#canvas"
✨  Done in 0.91s.

Your Environment

jarmitage commented 1 year ago

Same issue of 404 at https://github.com/Automattic/node-canvas/releases/download/v2.11.0/canvas-v2.11.0-node-v108-darwin-unknown-arm64.tar.gz

node v18.12.1 macOS 12.6

jarmitage commented 1 year ago

Fixed for me: brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

da-du commented 1 year ago

Fixed for me: brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

But is it the right way to install so many packages?

mn4367 commented 1 year ago

Fixed for me: brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

But is it the right way to install so many packages?

It's related to #2036 and other similar issues. Currently it still seems to be impossible to build a self contained version of canvas, so you have to install dependencies by other means.

Whobeu commented 1 year ago

I am running into this myself trying to run with Node.js 18 on Windows. There were no issues upgrading my Linux systems to Node.js 18 and "npm rebuild" worked fine. I am currently using Node.js 16.19.0 on Windows and it works fine. However, I just learned that the Node.js organization has moved the end-of-life for Node.js 16 forward seven months to September 2023, due to the OpenSSL end-of-life, so I realized I needed to look at Node.js 18 sooner than later for Windows.

UPDATE: I found the issue and it is rather odd. On Linux, everything works fine. "npm rebuild" updates the code to the latest Node platform. But on Windows it kept failing. Just for fun, I wiped the node_modules directory and did an "npm i". That worked. The correct node-canvas for Node 18 downloaded.

Kaisarion commented 1 year ago

can reproduce - macbook m1 ventura on a docker container any fixes? have tried everything from a source build to an npm ci

Orange-001 commented 1 year ago

Hey, guys! I also had the same issue. Maybe you can try creating an .npmrc file under the project root path, specifying the mirror address of the canvas, like this: canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas It worked for me and I hope it helps you.

LijiaHou commented 1 year ago

Hey, guys! I also had the same issue. Maybe you can try creating an .npmrc file under the project root path, specifying the mirror address of the canvas, like this: canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas It worked for me and I hope it helps you.

Wow, bro, you're so cool! I installed it in the Windows environment for two days without success until I used your method!

JianLin176 commented 1 year ago

大家好!我也有同样的问题。也许您可以尝试在项目根路径下创建一个 .npmrc 文件,指定画布的镜像地址,如下所示:canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas 它对我有用,希望对您有所帮助。

it work for me too.

kddsultan commented 1 year ago

In case someone is upgrading to Nodejs v18, upgrade might be the solution

Yurii397 commented 9 months ago

Fixed for me: brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

But is it the right way to install so many packages?

Looks it's expected way based on the canvas documentation - https://github.com/Automattic/node-canvas/wiki/Installation%3A-Mac-OS-X

Whobeu commented 9 months ago

Fixed for me: brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

But is it the right way to install so many packages?

Looks it's expected way based on the canvas documentation - https://github.com/Automattic/node-canvas/wiki/Installation%3A-Mac-OS-X

I have several Raspberry's that I use with node-canvas. Finally created myself a tiny bash script to handle it:

#!/bin/bash

read -p "Do you want to install the libraries for node-canvas? " -n 1 -r
echo    # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
  echo Installing packages required for installation of node-canvas
  sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
fi

There was a reason the -dev packages were required but I have forgotten.

335296558 commented 8 months ago

Fixed for me: brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

Mine is m1, this method helped me solve the problem

Imeth97 commented 7 months ago

I have the same issue, running yarn install --ignore-optional has fixed it for me for now. Canvas is only an optional dependency for react-pdf it seems

Suyash-Purwar commented 7 months ago

Fixed for me: brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

This doesn't fix anything for me. Using node version v14.21.3 on macOS 14.

bora001 commented 3 months ago

Fixed for me: brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

Brew install did't work for me, but after adding "node-gyp," it worked fine. (+ removed node_modules) If it still doesn't work for you, maybe you can try running "npm install" or "yarn" after downloading canvas individually.

pedroagcf commented 2 months ago

Fixed for me: brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

nguyenvhung9420 commented 3 weeks ago

Fixed for me: brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

Brew install did't work for me, but after adding "node-gyp," it worked fine. (+ removed node_modules) If it still doesn't work for you, maybe you can try running "npm install" or "yarn" after downloading canvas individually.

  • Solved : Added "node-gyp"
   "node-gyp": "^10.1.0",
  • Environment
  "canvas": "^2.11.2"
  "node": ">= v18.18.1",
  Mac : M1 macOS Ventura 13.4

Tks @bora001 your solution worked for me on Windows.