This error occurs when installing node-canvas without the required system dependencies. Install Cairo and related graphics libraries for your Linux distribution to fix it.
The node-canvas package is a Cairo-backed Canvas implementation for Node.js. It requires several native graphics libraries to be installed on your system before npm can build it. pkg-config is a helper tool that helps the build process find installed libraries. When it's missing, the compilation can't locate the required dependencies. This error commonly occurs on minimal server installations, Docker containers, or CI environments that don't include development libraries by default.
Install all required packages:
sudo apt-get update
sudo apt-get install -y \
build-essential \
libcairo2-dev \
libpango1.0-dev \
libjpeg-dev \
libgif-dev \
librsvg2-dev \
pkg-configFor Red Hat-based systems:
sudo yum install -y \
gcc-c++ \
cairo-devel \
pango-devel \
libjpeg-turbo-devel \
giflib-devel \
librsvg2-devel \
pkgconfigOn Fedora, use dnf instead of yum.
For Alpine (common in Docker):
apk add --no-cache \
build-base \
g++ \
cairo-dev \
pango-dev \
jpeg-dev \
giflib-dev \
librsvg-dev \
pkgconfigAfter installing dependencies, install canvas:
npm install canvasOr rebuild if already in package.json:
npm rebuild canvasFor Docker, add dependencies in your Dockerfile:
FROM node:20
# Install canvas dependencies
RUN apt-get update && apt-get install -y \
libcairo2-dev \
libpango1.0-dev \
libjpeg-dev \
libgif-dev \
librsvg2-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY package*.json ./
RUN npm ciFor multi-stage builds, remember that build dependencies are only needed in the build stage. The runtime stage needs the non-dev packages:
# Runtime stage only needs:
RUN apt-get update && apt-get install -y \
libcairo2 libpango-1.0-0 libjpeg62-turbo libgif7 librsvg2-2Consider using the canvas package's prebuilt binaries where available by checking their platform support documentation.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error