Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Error: Incompatibility of [email protected] with Node.js v22.11.0 #2448

Closed
bahram-della-ai opened this issue Oct 31, 2024 · 33 comments
Closed

Comments

@bahram-della-ai
Copy link

Description:

Hi there,

I'm experiencing build failures when trying to install [email protected] using Node.js v22.11.0. It appears there might be compatibility issues between this version of Node.js and the canvas module.

Environment:

  • Node.js Version: v22.11.0
  • Canvas Version: 2.11.2
  • Platform: Linux (Docker base image node:lts-slim as of October 2024)
  • Dependency Manager: npm

Steps to Reproduce:

  1. Dockerfile Setup:

    FROM node:lts-slim AS build
    RUN apt-get update && apt-get install -y --no-install-recommends \
        make \
        g++ \
        dumb-init \
        build-essential \
        libcairo2-dev \
        libpango1.0-dev \
        libjpeg-dev \
        libgif-dev \
        librsvg2-dev \
        python3 \
        && rm -rf /var/lib/apt/lists/*
    
    WORKDIR /usr
    COPY package*.json tsconfig.json ./
    RUN npm ci
  2. Install Dependencies:

  3. Observe the Build Failure:

    • The installation fails during the build process of canvas.

Error Log Highlights:

npm ERR! code 1
npm ERR! path /usr/node_modules/canvas
npm ERR! command failed
npm ERR! command sh -c node-pre-gyp install --fallback-to-build --update-binary
npm ERR! make: Entering directory '/usr/node_modules/canvas/build'
npm ERR!   SOLINK_MODULE(target) Release/obj.target/canvas-postbuild.node
npm ERR!   COPY Release/canvas-postbuild.node
npm ERR!   CXX(target) Release/obj.target/canvas/src/backend/Backend.o
npm ERR! In file included from ../src/backend/Backend.h:6,
npm ERR!                  from ../src/backend/Backend.cc:1:
npm ERR! ../../nan/nan.h: In function 'void Nan::SetAccessor(...)':
npm ERR! ../../nan/nan.h:2546:19: error: no matching function for call to 'v8::ObjectTemplate::SetAccessor(...)'
npm ERR! ...
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! node -v v22.11.0

Additional Information:

  • Downgrading to Node.js v20.x resolves the issue; canvas installs without errors.

Questions:

  1. Compatibility Confirmation:

    • Is [email protected] compatible with Node.js v22.11?
    • If not, are there plans to support Node.js v22.x in an upcoming release?
  2. Workarounds:

    • Are there any recommended steps or patches to make canvas work with Node.js v22.x?
  3. Dependency Updates:

    • Should we expect updates to dependencies like nan to address this compatibility issue?

Thank You:

Thank you for your time and assistance. Any guidance or updates on this matter would be greatly appreciated.

@gareth-johnstone
Copy link

This is also an issue for us, rolling back to version 20 FROM node:20-slim "fixes" the problem But not ideal.

@bahram-della-ai
Copy link
Author

This is also an issue for us, rolling back to version 20 FROM node:20-slim "fixes" the problem But not ideal.

We did not find a better solution either

@daimalou
Copy link

daimalou commented Nov 2, 2024

same

@usselman
Copy link

usselman commented Nov 2, 2024

Having the same issue.

@cmahnke
Copy link

cmahnke commented Nov 4, 2024

Binaries aren't found either:

node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v127-linux-glibc-x64.tar.gz
node-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-v127-linux-glibc-x64.tar.gz 
node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v127 ABI, glibc) (falling back to source compile with node-gyp) 

This happens on GitHub Actions, since I use actions/[email protected] with a version of lts/*, maybe the latest LTS has been changed?

@alvis
Copy link

alvis commented Nov 4, 2024

My workaround is to upgrade canvas to v3 RC, which removes some deprecated dependencies. However, note that it requires node-gyp version 10 for compilation. The version bundled with Node is often only version 9.

fproske added a commit to GAMS-dev/engine-ui that referenced this issue Nov 4, 2024
There is some build issue with node-canvas package on node:lts (22).
See: Automattic/node-canvas#2448
@daimalou
Copy link

daimalou commented Nov 5, 2024

It often happens that node-gyp fails with errors. It would be great if someone could rewrite it using napi-rs.

@cmahnke
Copy link

cmahnke commented Nov 5, 2024

@daimalou Have a look at https://github.com/Brooooooklyn/canvas

@usselman
Copy link

usselman commented Nov 5, 2024

For anyone coming to this in the future, I was able to migrate my canvas application very easily to https://github.com/samizdatco/skia-canvas

I also tried the above napi-rs/canvas but the Rust typing wasn't playing nice with my app, so the package I linked worked better for my use.

Hope this is fixed soon.

@cmahnke
Copy link

cmahnke commented Nov 5, 2024

Since no one mentioned it, but this is actually a problem known for some time:

Similar:

Let's face it, given there also is #2433 and the lastest release is one and a half years old it's safe to assume, that this package is't supported anymore. There isn't even a janitor for the issue tracker and the branch for the next version isn't active either.
Time (for downstream projects) to move on...

See ABI versions for the current LTS release here:
https://github.com/electron/node-abi/blob/main/abi_registry.json

@karlhorky
Copy link

karlhorky commented Nov 7, 2024

I encountered error messages about "Package pangocairo was not found in the pkg-config search path" with canvas not building today as I was trying to deploy with the current Node.js LTS (v22.10.0) on GitHub Actions.

This is after the first error ERR! install response status 404 Not Found, when it tries to download the precompiled binary, which doesn't exist (this error is a red herring because it's not important that the precompiled binaries don't exist, since we can build from source).

$ pnpm install

...

.../node_modules/canvas install$ node-pre-gyp install --fallback-to-build --update-binary
.../node_modules/canvas install: node-pre-gyp info it worked if it ends with ok
.../node_modules/canvas install: node-pre-gyp info using [email protected]
.../node_modules/canvas install: node-pre-gyp info using [email protected] | linux | x64
.../node_modules/canvas install: (node:1833) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
.../node_modules/canvas install: (Use `node --trace-deprecation ...` to show where the warning was created)
.../node_modules/canvas install: node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v127-linux-glibc-x64.tar.gz
.../node_modules/canvas install: node-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-v127-linux-glibc-x64.tar.gz 
.../node_modules/canvas install: node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v127 ABI, glibc) (falling back to source compile with node-gyp) 
.../node_modules/canvas install: 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-v127-linux-glibc-x64.tar.gz 
.../node_modules/canvas install: gyp info it worked if it ends with ok
.../node_modules/canvas install: gyp info using [email protected]
.../node_modules/canvas install: gyp info using [email protected] | linux | x64
.../node_modules/canvas install: gyp info ok 
.../node_modules/canvas install: gyp info it worked if it ends with ok
.../node_modules/canvas install: gyp info using [email protected]
.../node_modules/canvas install: gyp info using [email protected] | linux | x64
.../node_modules/canvas install: gyp info find Python using Python version 3.10.12 found at "/usr/bin/python3"
.../node_modules/canvas install: gyp http GET https://nodejs.org/download/release/v22.10.0/node-v22.10.0-headers.tar.gz
.../node_modules/canvas install: gyp http 200 https://nodejs.org/download/release/v22.10.0/node-v22.10.0-headers.tar.gz
.../node_modules/canvas install: gyp http GET https://nodejs.org/download/release/v22.10.0/SHASUMS256.txt
.../node_modules/canvas install: gyp http 200 https://nodejs.org/download/release/v22.10.0/SHASUMS256.txt
.../node_modules/canvas install: gyp info spawn /usr/bin/python3
.../node_modules/canvas install: gyp info spawn args [
.../node_modules/canvas install: gyp info spawn args '/home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/gyp/gyp_main.py',
.../node_modules/canvas install: gyp info spawn args 'binding.gyp',
.../node_modules/canvas install: gyp info spawn args '-f',
.../node_modules/canvas install: gyp info spawn args 'make',
.../node_modules/canvas install: gyp info spawn args '-I',
.../node_modules/canvas install: gyp info spawn args '/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/config.gypi',
.../node_modules/canvas install: gyp info spawn args '-I',
.../node_modules/canvas install: gyp info spawn args '/home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/addon.gypi',
.../node_modules/canvas install: gyp info spawn args '-I',
.../node_modules/canvas install: gyp info spawn args '/home/runner/.cache/node-gyp/22.10.0/include/node/common.gypi',
.../node_modules/canvas install: gyp info spawn args '-Dlibrary=shared_library',
.../node_modules/canvas install: gyp info spawn args '-Dvisibility=default',
.../node_modules/canvas install: gyp info spawn args '-Dnode_root_dir=/home/runner/.cache/node-gyp/22.10.0',
.../node_modules/canvas install: gyp info spawn args '-Dnode_gyp_dir=/home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp',
.../node_modules/canvas install: gyp info spawn args '-Dnode_lib_file=/home/runner/.cache/node-gyp/22.10.0/<(target_arch)/node.lib',
.../node_modules/canvas install: gyp info spawn args '-Dmodule_root_dir=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas',
.../node_modules/canvas install: gyp info spawn args '-Dnode_engine=v8',
.../node_modules/canvas install: gyp info spawn args '--depth=.',
.../node_modules/canvas install: gyp info spawn args '--no-parallel',
.../node_modules/canvas install: gyp info spawn args '--generator-output',
.../node_modules/canvas install: gyp info spawn args 'build',
.../node_modules/canvas install: gyp info spawn args '-Goutput_dir=.'
.../node_modules/canvas install: gyp info spawn args ]
.../node_modules/canvas install: Package pangocairo was not found in the pkg-config search path.
.../node_modules/canvas install: Perhaps you should add the directory containing `pangocairo.pc'
.../node_modules/canvas install: to the PKG_CONFIG_PATH environment variable
.../node_modules/canvas install: Package 'pangocairo', required by 'virtual:world', not found
.../node_modules/canvas install: gyp: Call to 'pkg-config pangocairo --libs' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
.../node_modules/canvas install: gyp ERR! configure error 
.../node_modules/canvas install: gyp ERR! stack Error: `gyp` failed with exit code: 1
.../node_modules/canvas install: gyp ERR! stack at ChildProcess.<anonymous> (/home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/lib/configure.js:317:18)
.../node_modules/canvas install: gyp ERR! stack at ChildProcess.emit (node:events:518:28)
.../node_modules/canvas install: gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:293:12)
.../node_modules/canvas install: gyp ERR! System Linux 6.5.0-1025-azure
.../node_modules/canvas install: gyp ERR! command "/opt/hostedtoolcache/node/22.10.0/x64/bin/node" "/home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--update-binary" "--module=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release" "--napi_version=9" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v127"
.../node_modules/canvas install: gyp ERR! cwd /home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas
.../node_modules/canvas install: gyp ERR! node -v v22.10.0
.../node_modules/canvas install: gyp ERR! node-gyp -v v10.2.0
.../node_modules/canvas install: gyp ERR! not ok 
.../node_modules/canvas install: node-pre-gyp ERR! build error 
.../node_modules/canvas install: node-pre-gyp ERR! stack Error: Failed to execute '/opt/hostedtoolcache/node/22.10.0/x64/bin/node /home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v127' (1)
.../node_modules/canvas install: node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/@[email protected][email protected]/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
.../node_modules/canvas install: node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:518:28)
.../node_modules/canvas install: node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1104:16)
.../node_modules/canvas install: node-pre-gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:304:5)
.../node_modules/canvas install: node-pre-gyp ERR! System Linux 6.5.0-1025-azure
.../node_modules/canvas install: node-pre-gyp ERR! command "/opt/hostedtoolcache/node/22.10.0/x64/bin/node" "/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/@[email protected][email protected]/node_modules/@mapbox/node-pre-gyp/bin/node-pre-gyp" "install" "--fallback-to-build" "--update-binary"
.../node_modules/canvas install: node-pre-gyp ERR! cwd /home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas
.../node_modules/canvas install: node-pre-gyp ERR! node -v v22.10.0
.../node_modules/canvas install: node-pre-gyp ERR! node-pre-gyp -v v1.0.11
.../node_modules/canvas install: node-pre-gyp ERR! not ok 
.../node_modules/canvas install: Failed to execute '/opt/hostedtoolcache/node/22.10.0/x64/bin/node /home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v127' (1)
.../node_modules/canvas install: Failed

Resolution: Upgrade to [email protected], install dependencies

Step 1: Before looking too deeply at the error message, I found recommendations to use [email protected] (recommendation 1, recommendation 2). So the first thing that I tried, before researching further about "pangocairo" was to upgrade to [email protected].

This didn't change the error message, the "Package pangocairo was not found in the pkg-config search path" was still in the logs.

Step 2: I researched the error message and found that the canvas docs recommend installing some dependencies for building from source:

Compiling

If you don't have a supported OS or processor architecture, or you use --build-from-source, the module will be compiled on your system. This requires several dependencies, including Cairo and Pango.

For detailed installation information, see the wiki. One-line installation instructions for common OSes are below. Note that libgif/giflib, librsvg and libjpeg are optional and only required if you need GIF, SVG and JPEG support, respectively. Cairo v1.10.0 or later is required.

OS Command
macOS Using Homebrew:
brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman python-setuptools
Ubuntu sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev

I saw that libcairo2-dev and libpango1.0-dev were dependencies and these seemed to match my error message "Package pangocairo was not found in the pkg-config search path".

I decided to try installing these dependencies in the GitHub Actions workflow:

      # https://github.com/Automattic/node-canvas/blob/a2e10e61413a0d158174a7a869c16aa13e5d3575/Readme.md?plain=1#L39
      - name: Install canvas dependencies
        run: sudo apt-get install libcairo2-dev libpango1.0-dev

This resolved the issue, as shown in the PR (unfortunately, also contains irrelevant changes):

What about [email protected]?

If you're still using the non-RC version, then you may receive an additional error "fatal error: gif_lib.h: No such file or directory":

.../node_modules/canvas install$ node-pre-gyp install --fallback-to-build --update-binary
.../node_modules/canvas install: node-pre-gyp info it worked if it ends with ok
.../node_modules/canvas install: node-pre-gyp info using [email protected]
.../node_modules/canvas install: node-pre-gyp info using [email protected] | linux | x64
.../node_modules/canvas install: (node:2048) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
.../node_modules/canvas install: (Use `node --trace-deprecation ...` to show where the warning was created)
.../node_modules/canvas install: node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v127-linux-glibc-x64.tar.gz
.../node_modules/canvas install: node-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-v127-linux-glibc-x64.tar.gz 
.../node_modules/canvas install: node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v127 ABI, glibc) (falling back to source compile with node-gyp) 
.../node_modules/canvas install: 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-v127-linux-glibc-x64.tar.gz 
.../node_modules/canvas install: gyp info it worked if it ends with ok
.../node_modules/canvas install: gyp info using [email protected]
.../node_modules/canvas install: gyp info using [email protected] | linux | x64
.../node_modules/canvas install: gyp info ok 
.../node_modules/canvas install: gyp info it worked if it ends with ok
.../node_modules/canvas install: gyp info using [email protected]
.../node_modules/canvas install: gyp info using [email protected] | linux | x64
.../node_modules/canvas install: gyp info find Python using Python version 3.10.12 found at "/usr/bin/python3"
.../node_modules/canvas install: gyp http GET https://nodejs.org/download/release/v22.10.0/node-v22.10.0-headers.tar.gz
.../node_modules/canvas install: gyp http 200 https://nodejs.org/download/release/v22.10.0/node-v22.10.0-headers.tar.gz
.../node_modules/canvas install: gyp http GET https://nodejs.org/download/release/v22.10.0/SHASUMS256.txt
.../node_modules/canvas install: gyp http 200 https://nodejs.org/download/release/v22.10.0/SHASUMS256.txt
.../node_modules/canvas install: gyp info spawn /usr/bin/python3
.../node_modules/canvas install: gyp info spawn args [
.../node_modules/canvas install: gyp info spawn args '/home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/gyp/gyp_main.py',
.../node_modules/canvas install: gyp info spawn args 'binding.gyp',
.../node_modules/canvas install: gyp info spawn args '-f',
.../node_modules/canvas install: gyp info spawn args 'make',
.../node_modules/canvas install: gyp info spawn args '-I',
.../node_modules/canvas install: gyp info spawn args '/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/config.gypi',
.../node_modules/canvas install: gyp info spawn args '-I',
.../node_modules/canvas install: gyp info spawn args '/home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/addon.gypi',
.../node_modules/canvas install: gyp info spawn args '-I',
.../node_modules/canvas install: gyp info spawn args '/home/runner/.cache/node-gyp/22.10.0/include/node/common.gypi',
.../node_modules/canvas install: gyp info spawn args '-Dlibrary=shared_library',
.../node_modules/canvas install: gyp info spawn args '-Dvisibility=default',
.../node_modules/canvas install: gyp info spawn args '-Dnode_root_dir=/home/runner/.cache/node-gyp/22.10.0',
.../node_modules/canvas install: gyp info spawn args '-Dnode_gyp_dir=/home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp',
.../node_modules/canvas install: gyp info spawn args '-Dnode_lib_file=/home/runner/.cache/node-gyp/22.10.0/<(target_arch)/node.lib',
.../node_modules/canvas install: gyp info spawn args '-Dmodule_root_dir=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas',
.../node_modules/canvas install: gyp info spawn args '-Dnode_engine=v8',
.../node_modules/canvas install: gyp info spawn args '--depth=.',
.../node_modules/canvas install: gyp info spawn args '--no-parallel',
.../node_modules/canvas install: gyp info spawn args '--generator-output',
.../node_modules/canvas install: gyp info spawn args 'build',
.../node_modules/canvas install: gyp info spawn args '-Goutput_dir=.'
.../node_modules/canvas install: gyp info spawn args ]
.../node_modules/canvas install: gyp info ok 
.../node_modules/canvas install: gyp info it worked if it ends with ok
.../node_modules/canvas install: gyp info using [email protected]
.../node_modules/canvas install: gyp info using [email protected] | linux | x64
.../node_modules/canvas install: gyp info spawn make
.../node_modules/canvas install: gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
.../node_modules/canvas install: make: Entering directory '/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build'
.../node_modules/canvas install:   SOLINK_MODULE(target) Release/obj.target/canvas-postbuild.node
.../node_modules/canvas install:   COPY Release/canvas-postbuild.node
.../node_modules/canvas install:   CXX(target) Release/obj.target/canvas/src/backend/Backend.o
.../node_modules/canvas install:   CXX(target) Release/obj.target/canvas/src/backend/ImageBackend.o
.../node_modules/canvas install:   CXX(target) Release/obj.target/canvas/src/backend/PdfBackend.o
.../node_modules/canvas install:   CXX(target) Release/obj.target/canvas/src/backend/SvgBackend.o
.../node_modules/canvas install:   CXX(target) Release/obj.target/canvas/src/bmp/BMPParser.o
.../node_modules/canvas install:   CXX(target) Release/obj.target/canvas/src/Backends.o
.../node_modules/canvas install:   CXX(target) Release/obj.target/canvas/src/Canvas.o
.../node_modules/canvas install:   CXX(target) Release/obj.target/canvas/src/CanvasGradient.o
.../node_modules/canvas install:   CXX(target) Release/obj.target/canvas/src/CanvasPattern.o
.../node_modules/canvas install: In file included from ../src/CanvasPattern.cc:6:
.../node_modules/canvas install: ../src/Image.h:18:10: fatal error: gif_lib.h: No such file or directory
.../node_modules/canvas install:    18 | #include <gif_lib.h>
.../node_modules/canvas install:       |          ^~~~~~~~~~~
.../node_modules/canvas install: compilation terminated.
.../node_modules/canvas install: make: *** [canvas.target.mk:163: Release/obj.target/canvas/src/CanvasPattern.o] Error 1
.../node_modules/canvas install: make: Leaving directory '/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build'
.../node_modules/canvas install: gyp ERR! build error 
.../node_modules/canvas install: gyp ERR! stack Error: `make` failed with exit code: 2
.../node_modules/canvas install: gyp ERR! stack at ChildProcess.<anonymous> (/home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/lib/build.js:216:23)
.../node_modules/canvas install: gyp ERR! System Linux 6.5.0-1025-azure
.../node_modules/canvas install: gyp ERR! command "/opt/hostedtoolcache/node/22.10.0/x64/bin/node" "/home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--update-binary" "--module=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release" "--napi_version=9" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v127"
.../node_modules/canvas install: gyp ERR! cwd /home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas
.../node_modules/canvas install: gyp ERR! node -v v22.10.0
.../node_modules/canvas install: gyp ERR! node-gyp -v v10.2.0
.../node_modules/canvas install: gyp ERR! not ok 
.../node_modules/canvas install: node-pre-gyp ERR! build error 
.../node_modules/canvas install: node-pre-gyp ERR! stack Error: Failed to execute '/opt/hostedtoolcache/node/22.10.0/x64/bin/node /home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --update-binary --module=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v127' (1)
.../node_modules/canvas install: node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/@[email protected][email protected]/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
.../node_modules/canvas install: node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:518:28)
.../node_modules/canvas install: node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1104:16)
.../node_modules/canvas install: node-pre-gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:304:5)
.../node_modules/canvas install: node-pre-gyp ERR! System Linux 6.5.0-1025-azure
.../node_modules/canvas install: node-pre-gyp ERR! command "/opt/hostedtoolcache/node/22.10.0/x64/bin/node" "/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/@[email protected][email protected]/node_modules/@mapbox/node-pre-gyp/bin/node-pre-gyp" "install" "--fallback-to-build" "--update-binary"
.../node_modules/canvas install: node-pre-gyp ERR! cwd /home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas
.../node_modules/canvas install: node-pre-gyp ERR! node -v v22.10.0
.../node_modules/canvas install: node-pre-gyp ERR! node-pre-gyp -v v1.0.11
.../node_modules/canvas install: node-pre-gyp ERR! not ok 
.../node_modules/canvas install: Failed to execute '/opt/hostedtoolcache/node/22.10.0/x64/bin/node /home/runner/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/dist/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --update-binary --module=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/home/runner/work/security-vulnerability-examples-next-js-postgres/security-vulnerability-examples-next-js-postgres/node_modules/.pnpm/[email protected][email protected]/node_modules/canvas/build/Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v127' (1)
.../node_modules/canvas install: Failed

This I tried to resolve in the same way, adding the dependency libgif-dev from the docs that matched the error message (in addition to the existing libcairo2-dev and libpango1.0-dev dependencies):

      # https://github.com/Automattic/node-canvas/blob/a2e10e61413a0d158174a7a869c16aa13e5d3575/Readme.md?plain=1#L39
      - name: Install canvas dependencies
        run: sudo apt-get install libcairo2-dev libpango1.0-dev libgif-dev

This also resolved the build issue, as shown in this PR:

@cmahnke
Copy link

cmahnke commented Nov 8, 2024

@karlhorky Thanks for your extensive and helpful analysis and hints!

Anyways: While it's still possible to build the module fro source not everyone either has the required tool chain (or even required knowledge) at had. And that should considered to be perfectly fine. Given that this module is also a dependency for pdf.js I guess there requirement might come to some as a surprise.

Same goes for the desire to run a pre release version - there are organisations where it's just imposible by policy / compilance frameworks etc..

And in the end it's just inefficient (also resource-wise as in Green-IT) to require users (of transitive dependency) to change their build infrastructure: Providing modules with C extensions is certainly another degree of responsibility, since those are more prone to break then native JS modules. Have a look at the pull requests, there are some to just automate those chores, but their not merged. These are clear indications to me that this project currently doesn't have the resources to support the code properly.

While I value your post, I would propose to other readers to use this to prepare a migration / transition.

@s-h-a-d-o-w
Copy link

I also tried the above napi-rs/canvas but the Rust typing wasn't playing nice with my app, so the package I linked worked better for my use.

Also, questionable professionalism. (Not to mention ethical and even possible legal problems. I am going to go delete my browser cache now...)
Thought I would point it out in case people don't bother scrolling down in the README.

@jylee9937
Copy link

same issue here. I use node 20.10.0

@jylee9937
Copy link

Step 2: I researched the error message and found that the canvas docs recommend installing some dependencies for building from source:

Compiling

If you don't have a supported OS or processor architecture, or you use --build-from-source, the module will be compiled on your system. This requires several dependencies, including Cairo and Pango.
For detailed installation information, see the wiki. One-line installation instructions for common OSes are below. Note that libgif/giflib, librsvg and libjpeg are optional and only required if you need GIF, SVG and JPEG support, respectively. Cairo v1.10.0 or later is required.

OS
Command

macOS
Using Homebrew:brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman python-setuptools

Ubuntu
sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev

I saw that libcairo2-dev and libpango1.0-dev were dependencies and these seemed to match my error message "Package pangocairo was not found in the pkg-config search path".

I decided to try installing these dependencies in the GitHub Actions workflow:

  # https://github.com/Automattic/node-canvas/blob/a2e10e61413a0d158174a7a869c16aa13e5d3575/Readme.md?plain=1#L39
  - name: Install canvas dependencies
    run: sudo apt-get install libcairo2-dev libpango1.0-dev

This resolved the issue, as shown in the PR (unfortunately, also contains irrelevant changes):

@karlhorky Thank you. I took a hint from your article and solved the problem that was with me.

I'm using Fabric.js, so I didn't think I could solve the error in canvas 2.11.0 myself.

The error message I had is as follows.
"node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v115-linux-musl-x64.tar.gz"

However, as written in the document, if you installed the packages to compile and use them on your own, there was no error when you did yarn.

Since yesterday, I haven't been built, but I've finally solved it.

@bennycode
Copy link

Same issue on Windows:

npm error code 1
npm error path /home/bennycode/dev/bennycode/vorsorgi/node_modules/canvas
npm error command failed
npm error command sh -c node-pre-gyp install --fallback-to-build --update-binary
npm error Failed to execute '/home/bennycode/.nvm/versions/node/v22.11.0/bin/node /home/bennycode/.nvm/versions/node/v22.11.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/home/bennycode/dev/bennycode/vorsorgi/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/home/bennycode/dev/bennycode/vorsorgi/node_modules/canvas/build/Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v127' (1)
npm error node-pre-gyp info it worked if it ends with ok
npm error node-pre-gyp info using [email protected]
npm error node-pre-gyp info using [email protected] | linux | x64

@sahal
Copy link

sahal commented Nov 18, 2024

I've checked to make sure that this is working on multiple node versions from 18-23. I've installed canvas by adding it to a blank project using yarn. It seems to be working when I just install canvas. Here is my build setup using Docker/Podman: https://gist.github.com/sahal/ec57d2e63764e7b125fca54267977bdc.

Logs: build-canvas-yarn-18-23-verbose.txt

I am, however, having problems when running my Joplin install when using node 23 (see linked ticket). It seems to fail when building [email protected]. I'm not a js dev, so I'm not sure why that might be though. Will follow up with my build logs for Joplin in the linked issue.

@umeshramya
Copy link

I am also facing issues with the canvas module not building on Node.js version 22.11.0, which is the default version on many cloud platforms. Resolving this has become a priority now.

@cmahnke
Copy link

cmahnke commented Nov 23, 2024

@umeshramya : Consider the priority to be to replace canvas...
If it's an indirect dependency raise an issue upstream.

@MattinaYang
Copy link

I solved this by running apk add --no-cache build-base g++ cairo-dev jpeg-dev pango-dev giflib-dev first. (linux)

@imawizrd
Copy link

imawizrd commented Dec 4, 2024

Canvas failed to install with Yarn on macOS and NodeJS 22.7.0 because it couldn't find online binaries. I had installed all dependencies, but it still failed to build due to a missing environment.

You need to configure the PKG_CONFIG_PATH environment variable with all the pkgconfig paths. Instead of doing it manually, you can use instructions from this Super User answer:

find /usr/local/Cellar -name 'pkgconfig' -type d | tr '\n' ':' | sed s/.$//

In your ~/.zshrc add:

export PKG_CONFIG_PATH="...output from previous command..."

Just a heads-up, this output is versioned, so you might need to maintain it after Homebrew updates, but don't do it manually. It could be hundreds of dependencies, instead use this script to update it (it assumes zsh is the default shell and bash 3):

#!/bin/bash

# Get the new value from the command. This is the versioned command mentioned before.
NEW_VALUE="$(find /usr/local/Cellar -name 'pkgconfig' -type d | tr '\n' ':' | sed s/.$//)"

# Check if the variable is already set.
if grep -q "export PKG_CONFIG_PATH" ~/.zshrc; then
  # Replace the old value with the new value. Use a sed delimiter that's unlikely to appear in a file path. 
  # It will also back up the previous configuration.
  sed -i.bak "s#export PKG_CONFIG_PATH=.*#export PKG_CONFIG_PATH=\"$NEW_VALUE\"#g" ~/.zshrc
else
  # Add the variable if it's not already set.
  echo "export PKG_CONFIG_PATH=\"$NEW_VALUE\"" >> ~/.zshrc
fi

After setting this variable Canvas builds successfully.

@TravisJRyan
Copy link

Hi @chearon would it be possible to get prebuilt binaries released for Node 22.11.0, given node-canvas 3.0 is still an rc? I'm still not sure from the above discussion if there is an incompatibility blocking this or if we just need binaries to be released.

Thanks in advance.

@chearon
Copy link
Collaborator

chearon commented Dec 5, 2024

I think it's just prebuilds: canvas 2.11.2 doesn't have binaries for Node 22. It would be difficult to update the binaries for 2.11.2 since the prebuild scripts have to change so much in order to build 3.0, but I could make an attempt at running the old script. The prebuilds are a massive pain and what's holding everything back. I've got some time carved out this weekend to try to get 3.0 released, though.

@TravisJRyan
Copy link

TravisJRyan commented Dec 9, 2024

Hi @chearon just following up to see if running the old script was successful or if the only path forward is to set up build tooling to build this yourself.

And in the latter case, in an enterprise environment, would it be possible for us to build our own prebuilt and host it on a custom mirror?

Thanks again for having a look here.

@Setitch
Copy link

Setitch commented Dec 17, 2024

Yes, this is not building on 22 version

@Sieabah
Copy link

Sieabah commented Dec 21, 2024

Canvas doesn't build on v22 or v20 for me. 👌 I think it's been 5 years of consistent issues just getting this package to install at all. Even within a docker container is risky, it's easier to build a container that has this working once then use that as the base image for everything else. It sucks if you need to update anything like security packages, but hey, that's the "Wordpress-Company" way.

npm error gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm error In file included from ../src/backend/Backend.cc:1:
npm error ../src/backend/Backend.h:5:10: fatal error: 'exception' file not found
npm error     5 | #include <exception>
npm error       |          ^~~~~~~~~~~
npm error 1 error generated.
npm error make: *** [Release/obj.target/canvas/src/backend/Backend.o] Error 1
npm error gyp ERR! build error
npm error gyp ERR! stack Error: `make` failed with exit code: 2
npm error gyp ERR! stack at ChildProcess.<anonymous> (/Users/usrname/.nvm/versions/node/v22.12.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:216:23)
npm error gyp ERR! System Darwin 24.2.0
npm error gyp ERR! command "/Users/usrname/.nvm/versions/node/v22.12.0/bin/node" "/Users/usrname/.nvm/versions/node/v22.12.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--update-binary" "--module=/Users/usrname/IdeaProjects/proj/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/Users/usrname/IdeaProjects/proj/node_modules/canvas/build/Release" "--napi_version=9" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v127"
npm error gyp ERR! cwd /Users/usrname/IdeaProjects/proj/node_modules/canvas

Just downgrade

I've downgraded all the way down to node 16. I've gone from 2.11.2 down a few versions and it still didn't work. wasm-sjlj also is imported dynamically during the canvas build and that was also causing gyp issues (now fixed). I think Automattic really needs to consider if they should be investing in consistent compilation/builds instead of lawsuits.

You gotta update your deps

Ok.

✗ brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman python-setuptools
Warning: pkgconf 2.3.0_1 is already installed and up-to-date.
To reinstall 2.3.0_1, run:
  brew reinstall pkgconf
Warning: cairo 1.18.2 is already installed and up-to-date.
To reinstall 1.18.2, run:
  brew reinstall cairo
Warning: pango 1.55.5 is already installed and up-to-date.
To reinstall 1.55.5, run:
  brew reinstall pango
Warning: libpng 1.6.44 is already installed and up-to-date.
To reinstall 1.6.44, run:
  brew reinstall libpng
Warning: jpeg 9f is already installed and up-to-date.
To reinstall 9f, run:
  brew reinstall jpeg
Warning: giflib 5.2.2 is already installed and up-to-date.
To reinstall 5.2.2, run:
  brew reinstall giflib
Warning: librsvg 2.58.4 is already installed and up-to-date.
To reinstall 2.58.4, run:
  brew reinstall librsvg
Warning: pixman 0.44.2 is already installed and up-to-date.
To reinstall 0.44.2, run:
  brew reinstall pixman
Warning: python-setuptools 75.6.0 is already installed and up-to-date.
To reinstall 75.6.0, run:
  brew reinstall python-setuptools

I must have already done that at some point.

Downgrade your OS

Ok. Tried it on Sonoma 14 and 15, both fail. Windows 10, & Ubuntu 22.04.

Do X

I've already decided to drop this package entirely because after 5 years this still doesn't have a reliable build toolchain. The devs can decide to fix the actual problem or suggest broken solutions which last a few months before the same root issue causes another build problem. I've wasted days trying to resolve what exactly is missing, y'all can spend some time just making this usable. 👋

Have you verified it's not another dep?

Yeah. If I remove "canvas" all of my install problems go away.

@cmahnke
Copy link

cmahnke commented Dec 22, 2024

@Sieabah: Please read the above carefully. Instead of complaining, get rid of this package and encourage others to do so as well...
There are at least alternative packages linked above.

@Sieabah
Copy link

Sieabah commented Dec 22, 2024

@cmahnke I already swapped to @napi-rs/canvas, but it is absolutely not 1:1 compatible. Anything dealing with clipping masks just doesn't work, or doesn't work identically. So I have to have alternative code on the backend node renderer vs the frontend browser renderer. I'm moving to just rewrite what I do with canvas into something else entirely (both frontend & backend). I guess you found the edge case that I didn't mock in my complaint. This isn't a solution or "answer" that actually solves the problem...

I'm not going to go back through the comments and install random shit or create work for me to maintain this setup across OS's and dev laptops. I identified that this package is pulling unpinned deps and expecting it to "just work". No, I'm not making a PR to fix them because I'm not signing myself up to maintain that, nor do I want to have to negotiate that through a merge process. I'm aware of what people have tried here because I've been dealing with this package having install issues for years. It'll eventually work then break, then work, then break. All the while the version has been pinned the whole time.

What good does using a separate package do to fixing this one? It would be nice if this package just worked instead of it being so problematic. I wanted to express that more than temporary solutions that someone will be trying a year from now when it's broken again, begging for it to work.

@cmahnke
Copy link

cmahnke commented Dec 23, 2024

@Sieabah I hope, you're not getting me wrong, but my point of view on this issue is: This module had it's problems for years, you also mentioned them. They are scattered across this issue tracker.

In the end those (and a few more) are a clear indication that the development model / priorities for this project are a bit of.
This is the real problem.
As solving anything else (technical) won't save users from all the problems there were in the past to reappear in the future. From what I understand we can agree on this.
I would extend your points to the lack of prebuild binaries, the absence of a 2.x branch (which might lead to problems as well) and the heavy focus on a 3 alpha instead of fixing what's already broadly used.
In the end, those are systematic issues, apart from any technical questions. Or to put it bluntly: Fixing the (release / QA) process hasn't been a long term goal at all, why should that change over night?

That being said, I don't see any reasons why this should be fixed at all and instead try to find a good replacement...
If that has issues in being a drop in replacement, it might be worthwhile to help to fix those instead of waiting for Santa Claus here.

Or you just try another package like Canvaskit-WASM

@FrancescoBorzi
Copy link

The following helped me on Debian Bookworm. Probably does not resolve the original issue here but I'm still posting it hoping to help someone out there.

apt-get update && apt-get install -y \
    build-essential \
    libcairo2-dev \
    libpango1.0-dev \
    libjpeg-dev \
    libgif-dev \
    librsvg2-dev

@chearon
Copy link
Collaborator

chearon commented Dec 23, 2024

I've released 3.0.0 which removes NAN, so this should be fixed. The only breaking change for 3.0.0 was dropping support for old Node versions, so users of Node 22 should be able to safely upgrade.

@chearon chearon closed this as completed Dec 23, 2024
@dgtllion
Copy link

@chearon do i understand good that we dont need any apt-get installs like this below after upgrading to v3?

apt-get update && apt-get install -y \
    build-essential \
    libcairo2-dev \
    libpango1.0-dev \
    libjpeg-dev \
    libgif-dev \
    librsvg2-dev

@karlhorky
Copy link

karlhorky commented Dec 28, 2024

@dgtllion correct, I can confirm that with [email protected], the extra build dependencies like libcairo2-dev and libpango1.0-dev are no longer needed (at least for the GitHub Actions Ubuntu environment).

I removed the GitHub Actions step in this PR:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests