I have a Node.js app that creates PDF files using Puppeteer and it works fine locally but fails when deployed to DigitalOcean App Platform. The error says it can’t find Chromium at the path I specified.
My Setup:
- DigitalOcean App Platform deployment
- Node.js 20.x with latest Puppeteer
- Using .aptfile to install Chromium
Here’s my PDF generation code:
const express = require('express');
const puppeteer = require('puppeteer');
const handlebars = require('handlebars');
const fs = require('fs');
const server = express();
const PORT = 5000;
// Template compilation
const templateSource = fs.readFileSync('./views/report.hbs', 'utf8');
const template = handlebars.compile(templateSource);
server.use(express.json());
server.post('/create-report', async (req, res) => {
try {
const reportData = req.body;
// Process data
const netAmount = reportData.items.reduce((total, item) => total + item.cost, 0);
const taxAmount = netAmount * 0.2;
const finalTotal = netAmount + taxAmount;
const currentDate = new Date().toLocaleDateString();
// Create HTML from template
const htmlContent = template({
data: reportData,
netAmount,
taxAmount,
finalTotal,
date: currentDate
});
// Launch browser and create PDF
const browserInstance = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage'
],
executablePath: '/layers/digitalocean_apt/apt/usr/bin/chromium-bsu'
});
const newPage = await browserInstance.newPage();
await newPage.setContent(htmlContent);
const pdfData = await newPage.pdf({ format: 'A4', printBackground: true });
await browserInstance.close();
res.contentType('application/pdf');
res.send(pdfData);
} catch (err) {
console.error('PDF creation failed:', err);
res.status(500).json({ message: 'Could not create PDF' });
}
});
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
My .aptfile contains:
chromium
chromium-common
chromium-sandbox
fonts-liberation
libatk-bridge2.0-0
libasound2
Error message I’m getting:
Browser was not found at the configured executablePath (/layers/digitalocean_apt/apt/usr/bin/chromium-bsu)
The browser path seems wrong but I’m not sure what the correct path should be for DigitalOcean App Platform. Has anyone solved this before?