Demo, all content is generated
Question

Puppeteer works on my laptop, on Vercel: Could not find Chrome

Open · 523 views · asked by santi_dev_wannabe · edited

I generate PDF invoices with Puppeteer in an API route. Local fine. On Vercel:

Error: Could not find Chrome (ver. 127.0.6533.88). This can occur if either
 1. you did not perform an installation before running the script (e.g. npx puppeteer browsers install chrome) or
 2. your cache path is incorrectly configured
What I’ve tried

Added "npx puppeteer browsers install chrome" as postinstall. Build worked but same error at runtime. Then the function went over the size limit.

Comment
Which plan, and how big is the function bundle after your postinstall? deploydan · edited

2 answers

deploydan · edited

Full Puppeteer downloads a ~170MB Chrome that doesn't fit in a serverless function. The usual setup is puppeteer-core + @sparticuz/chromium (a trimmed Chromium built for Lambda-style environments):

import chromium from "@sparticuz/chromium";
import puppeteer from "puppeteer-core";

const browser = await puppeteer.launch({
  args: chromium.args,
  executablePath: await chromium.executablePath(),
  headless: true,
});

Match the @sparticuz/chromium major version to what your puppeteer-core version expects. Give the function enough memory (1GB+).

Comment
it deploys now! first PDF takes 6 seconds though santi_dev_wannabe · edited
dmitri_v · edited

For invoices specifically I'd drop the browser entirely. @react-pdf/renderer or pdf-lib generate PDFs in plain Node, no Chrome, fast and tiny. Headless Chrome is worth it when you need to render an existing web page exactly.

Comment
Agree, if the layout is simple that's the better long-term setup. deploydan · edited
trying react-pdf this weekend, 6 seconds cold start is too much for an invoice santi_dev_wannabe · edited