I want to generate pdf from puppeteer package. I am using docker and nestjs as language. When I try to run the code, it says Error: Failed to launch the browser process! spawn /usr/bin/chromium-browser ENOENT My current OS is macos m1 chip
Now, I have tried many things Used these and also changes headless property to false;
puppeteer.launch({
dumpio: true,
headless: true,
executablePath: "/usr/bin/chromium-browser",
args: ["--disable-setuid-sandbox", "--no-sandbox", "--disable-gpu"],
});
Dockerfile
FROM node:14.18.1 As development
WORKDIR /usr/src/app
COPY package*.json ./
RUN apt-get update && apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
RUN apt-get install -y \
fonts-liberation \
gconf-service \
libappindicator1 \
libasound2 \
libatk1.0-0 \
libcairo2 \
libcups2 \
libfontconfig1 \
libgbm-dev \
libgdk-pixbuf2.0-0 \
libgtk-3-0 \
libicu-dev \
libjpeg-dev \
libnspr4 \
libnss3 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libpng-dev \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
xdg-utils
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
RUN npm i puppeteer
RUN chmod -R o+rwx node_modules/puppeteer/.local-chromium
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
RUN npm install --only=development
COPY . .
RUN npm install rimraf
RUN npm run build
FROM node:14.2.0 as production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
COPY . .
COPY --from=development /usr/src/app/dist ./dist
CMD ["node", "dist/main"]
Here is my code
const browser = await puppeteer.launch({
dumpio: true,
headless: true,
executablePath: "/usr/bin/chromium-browser",
args: ["--disable-setuid-sandbox", "--no-sandbox", "--disable-gpu"],
});
// create a new page(opening a new tab with new page)
const page = await browser.newPage();
// set html inside page
await page.setContent(html);
// provide some options(eg: width, height) to page
const pdfBuffer = await page.pdf(options);
// clear out our Puppeteer instance to free memory
await page.close();
await browser.close();
console.log("PDF buffer is", pdfBuffer);
return pdfBuffer;
} catch (error) {
console.log("Error is", error);
}
There many solutions for these, I tried most of the links, but none of them are working out. Its almost been 2hrs, but I am not able to reach solution for it.
Some of the things are tried out: