I am using puppeteer in sveltekit project to convert the html into pdf file. In local machine if i run sveltekit project then its working fine without any issue, but after the deployment in server its not working and getting error:
Failed to launch the browser process!
rosetta error: failed to open elf at /lib64/ld-linux-x86-64.so.2
I am using following function to convert html content to pdf:
async function generatePdfWithPuppeteer(htmlContent) {
const browser = await puppeteer.launch({
headless: true,
executablePath: puppeteer.executablePath(), // Ensure Puppeteer uses its bundled Chromium
args: ['--no-sandbox', '--disable-setuid-sandbox'] // For environments like Docker
});
const page = await browser.newPage();
await page.setContent(htmlContent, { waitUntil: 'networkidle0' });
const pdfBuffer = await page.pdf({
format: 'A4',
printBackground: true,
margin: {
top: '20mm',
bottom: '20mm',
left: '15mm',
right: '15mm'
}
});
await browser.close();
return pdfBuffer;
}
In server its serving using Docker. When i check docker file then i found that
# Use an official Node.js runtime as a parent image
FROM node:18-slim
# Install dependencies for Puppeteer to run Chromium
RUN apt-get update && apt-get install -y \
wget \
ca-certificates \
fonts-liberation \
libappindicator3-1 \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libcups2 \
libgdk-pixbuf2.0-0 \
libnspr4 \
libnss3 \
libx11-xcb1 \
libxcomposite1 \
libxdamage1 \
libxrandr2 \
xdg-utils \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
# Set the working directory
WORKDIR /app
# Copy the package.json and package-lock.json (or yarn.lock)
COPY package*.json ./
# Install dependencies
RUN npm install
RUN npm install puppeteer --arch=arm64
# Copy the rest of the application files
COPY . .
# Expose the port
EXPOSE 8000
# Build the SvelteKit project
RUN npm run build
# Start the application (for production mode)
CMD ["npm", "run", "preview"]
Is there any way to fix this issue, It might be really helpful.