Open Vigintillionn opened 1 month ago
I'm facing the same issue. If you manage to solve it, let me know.
I managed to solve the problem. The issue lies in the node_modules folder. Once Canvas is installed in node_modules on the local machine (in my case, Windows), and you try to create the Docker image from your local machine, for some reason, Canvas throws an error. I believe it signs something in its package specific to that environment, and when the Docker image is generated, it tries to use the node_modules from the PC, causing an issue. Either you delete the node_modules folder from the project before generating the Docker image, or you add a .dockerignore file and ignore node_modules, similar to how .gitignore works.
I already have a dockerignore file with node_modules in. Would you mind sharing your dockerfile?
FROM node:20
canvas
RUN apt-get update && apt-get install -y \ build-essential \ libcairo2-dev \ libpango1.0-dev \ libjpeg-dev \ libgif-dev \ librsvg2-dev \ libtool \ autoconf \ automake \ && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn
RUN yarn add canvas
COPY . .
RUN yarn build
RUN yarn global add pm2
EXPOSE 3333
RUN ./node_modules/.bin/typeorm migration:run
CMD ["pm2-runtime", "start", "ecosystem.config.js"]
This unfortunately did not resolve my issue. I still am receiving the same error.
Access the node-canvas documentation -> https://www.npmjs.com/package/canvas Sometimes you might be using methods that are only supported in the browser and not in the backend.
I'm only using the createCanvas method.
Issue or Feature
I've been trying to get canvas to work in a docker container, running a discord bot. I can install canvas without issues, the problem is canvas won't run. Nor on node:20 nor node:20-alpine. Has anyone had this happen to them and possibly knows a solution to this? Here's the error I'm getting
libjpeg8 is no longer part of debian nor alpine. I tried installing it but that didn't work either. Then I tried installing
libjpeg62-turbo
and create a symlink, but that didn't work either.The code runs fine outside of my container (on my arch machine).
Steps to Reproduce
Here's my docker container:
Your Environment
npm list canvas
oryarn list canvas
): canvas@2.11.2