M1 chip, Install Puppeteer in Docker NodeJs, The chromium binary is not available for arm64
Asked Answered
G

6

13

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"]
Goldwin answered 16/11, 2021 at 2:22 Comment(1)
Have you found a solution to this? A member of my team is facing the same issue. Please add an answer if you found a way to make it work. ThxTimetable
T
7

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

Tinea answered 18/5, 2022 at 15:7 Comment(3)
I had to add the following command to install chromium on my M2 mac, but thanks for the tip! RUN apt-get update && apt-get install -yq chromiumParesis
I inherited a project which used FROM node:14.17-buster instead of current-alpine. As such, I had to use apt-get instead of apk, just as @Paresis did above, along with the ENV statements.Pushkin
I also had to change PUPPETEER_EXECUTABLE_PATH to /usr/bin/chromiumPushkin
O
0

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
Oralle answered 6/5, 2022 at 9:47 Comment(1)
I was trying to run a repo that contained puppeteeras a dependency and npm install didn't work on Mac, so I just prepended the environment variable with npm install and it worked: PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm installLackadaisical
T
0

For anyone that is:

  • using Docker
  • doesn't want to switch to alpine
  • having issues with Some index files failed to download. They have been ignored, or old ones used instead.

you need to add the archive link to the container's sources.list like so:

# Patch sources list for chromium and other packages that have been archived
RUN echo "deb http://archive.debian.org/debian stretch main" > /etc/apt/sources.list
Trivalent answered 11/7, 2023 at 7:17 Comment(0)
S
0

Here is a working dockerfile for running puppeteer on an arm based docker container.

FROM --platform=linux/arm64 ubuntu:22.04

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y gconf-service apt-transport-https ca-certificates libssl-dev wget libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils curl build-essential tar gzip findutils net-tools dnsutils telnet ngrep tcpdump
RUN apt-get install software-properties-common -y 
RUN add-apt-repository ppa:saiarcot895/chromium-dev

RUN apt update
RUN apt-get install -y chromium-browser


ENV NODE_VERSION 14.17.0

RUN ARCH=arm64 \
  && curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
  && tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
  && rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
  && ln -s /usr/local/bin/node /usr/local/bin/nodejs \
  # smoke tests
  && node --version \
  && npm --version

RUN ARCH=arm64 \
  && npm install -g [email protected]

ENTRYPOINT ["/bin/sh", "-c", "bash"]
Scintillate answered 24/4 at 12:40 Comment(0)
Y
0

I was getting the same issue with Nest JS and the library @nestjs-html-pdf too the library was using puppeteer under the hood. Also am in Mac M1 too, So i have fixed the problem following this steps:

1. brew install chromium --no-quarantine

2. Exporting puppeteer variables ~/.zshrc file

export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
export PUPPETEER_EXECUTABLE_PATH=`which chromium`

3. In my docker file i add this line, at the top of the file.

FROM node:20.6.0 <- Your version

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true 

4. And in my .env file (Optional, if the dockerfile env doesn't works)

export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true

I Hope this can help any one with the same problem. If you have questions or something like that please let me know : )

Yanirayank answered 23/5 at 23:41 Comment(1)
UPDATE [June 16] - I was using the library @saemhco/nestjs-html-pdf that includes Puppeter in their dependencies after several hours trying to make work puppeter with Docker in production (Production is in a Windows Server) i prefered to move to other library (pdf-creator-node). If this is your case, the fast way is to move to another library. IMPORTANT: Puppeter works in dev with the solution above.Yanirayank
E
-2

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
Equipotential answered 24/12, 2021 at 10:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.