Hey everyone, I’m having a headache with my Node.js app on AWS EC2. I’m trying to use Puppeteer to turn HTML into PDF, but it’s not working. The error message says it can’t find Chrome version 113.0.5672.63. It’s driving me crazy!
I’ve already tried a few things:
- Set
PUPPETEER_SKIP_DOWNLOAD=true
as an environment variable
- Played around with different Node versions
Nothing seems to work. The error keeps talking about installation issues or cache path problems. My production server is crashing because of this.
Here’s a simplified version of what I’m trying to do:
const puppeteer = require('puppeteer');
async function htmlToPdf(htmlContent) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(htmlContent);
const pdf = await page.pdf();
await browser.close();
return pdf;
}
But it never gets past the puppeteer.launch()
part. Any ideas on how to fix this? I’m completely stuck!
I’ve dealt with this exact issue before on EC2. The problem is likely that Puppeteer can’t find a compatible Chrome version on your instance. Here’s what worked for me:
-
Install the necessary dependencies:
sudo amazon-linux-extras install epel
sudo yum update
sudo yum install -y chromium
-
In your Node.js code, specify the Chrome executable path:
const browser = await puppeteer.launch({
executablePath: ‘/usr/bin/chromium-browser’,
args: [‘–no-sandbox’, ‘–disable-setuid-sandbox’]
});
This approach bypasses Puppeteer’s built-in Chrome and uses the system-installed Chromium instead. It should resolve the version mismatch and get your PDF generation working.
Also, make sure your EC2 instance has enough memory, as Puppeteer can be resource-intensive. If you’re still having issues, double-check your security groups to ensure outbound connections are allowed for downloading dependencies.
I encountered a similar issue when deploying a Puppeteer-based application on EC2. The solution that worked for me was using a custom AWS Lambda Layer with Chromium included. This approach eliminated the need to install Chromium on the EC2 instance directly.
To implement this, I created a Lambda Layer with Chromium and its dependencies, then referenced it in my EC2 instance. In the application code, I specified the Chromium executable path to this custom layer.
const browser = await puppeteer.launch({
executablePath: ‘/opt/chromium/chrome’,
args: [‘–no-sandbox’, ‘–disable-gpu’]
});
This method ensured consistent Chromium versions across deployments and resolved version mismatch errors. It also improved performance by reducing instance startup time. Consider giving this approach a try if other solutions haven’t worked for you.
hey alice45, i had similar issues. try installing chromium separately on ur EC2 instance. use ‘sudo yum install chromium’ for amazon linux. then point puppeteer to the chromium binary path in ur code. might solve ur problem without messin with env variables or node versions.