'M1 chip, Install Puppeteer in Docker NodeJs, The chromium binary is not available for arm64
I got an error while building backend docker, specifically installing Puppeteer. I'm using M1 MacBook, and I found a solution on the local machine(https://github.com/puppeteer/puppeteer/issues/6622), but this didn't work on the docker. Has anyone who has the same Puppeteer issue on the docker?
#12 15.58 npm ERR! code 1
#12 15.58 npm ERR! path /app/node_modules/puppeteer
#12 15.58 npm ERR! command failed
#12 15.58 npm ERR! command sh -c node install.js
#12 15.58 npm ERR! The chromium binary is not available for arm64.
#12 15.58 npm ERR! If you are on Ubuntu, you can install with:
#12 15.58 npm ERR!
#12 15.58 npm ERR! sudo apt install chromium
#12 15.58 npm ERR!
#12 15.58 npm ERR!
#12 15.58 npm ERR! sudo apt install chromium-browser
#12 15.58 npm ERR!
#12 15.58 npm ERR! /app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:115
#12 15.58 npm ERR! throw new Error();
FROM --platform=linux/amd64 node:16-alpine
WORKDIR /app
EXPOSE 8000
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV DOCKER_DEFAULT_PLATFORM "linux/amd64"
COPY . .
RUN apk --no-cache add --virtual builds-deps build-base python3 && \
npm install
CMD ["npm", "start"]
Solution 1:[1]
I had the same error, and this made it work for me: https://github.com/puppeteer/puppeteer/issues/7740#issuecomment-970490323
It seems the npm installation cannot find a chromium binary for M1. To not make npm try to install Chromium, you can add ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
. But then I needed to also install the binary before running npm install
, by adding RUN apk add chromium
to the Dockerfile (if you are running the node alpine image).
Result:
FROM node:16-alpine
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
RUN apk add chromium
# Add and install everything
Solution 2:[2]
This is the dockerfile that worked for me.
# reference https://developers.google.com/web/tools/puppeteer/troubleshooting#setting_up_chrome_linux_sandbox
FROM node:current-alpine
# manually installing chrome
RUN apk add chromium
# skips puppeteer installing chrome and points to correct binary
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
WORKDIR /app
COPY ["package.json", "package-lock.json*", "./"]
RUN npm ci
# the rest of your dockerfile here
When launching puppeteer in js, make sure to add the following flags on launch
puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
You can read more about this in google's docs
Solution 3:[3]
Add puppeteer env after building dependencies. Worked for me.
FROM node:16-alpine3.11
WORKDIR /usr/app
COPY package*.json ./
COPY tsconfig.json ./
RUN apk --no-cache --virtual build-dependencies add \
python3 \
make \
g++
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
RUN npm install --quiet
RUN npm install -g pm2 --quiet
COPY ./ ./
RUN npm run build
RUN rm -rf ./src
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | William |
Solution 2 | MikalKotadia |
Solution 3 | pzaenger |