Deploying Puppeteer with Next.js on Vercel | Vercel Knowledge Base

Puppeteer is a powerful Node.js library that provides a high-level API to control headless Chrome or Chromium. It's incredibly useful for automating browser tasks like generating screenshots, creating PDFs, and scraping websites. Running Puppeteer in a serverless environment like Vercel, however, requires specific configuration to work within the platform's constraints.

This guide provides a general walkthrough for deploying a Next.js application with Puppeteer to Vercel. We will use a screenshot generator as a practical example to demonstrate the key concepts.

Prerequisites

Key Concepts for Puppeteer on Vercel

To successfully run Puppeteer in a Vercel Function, you must address the function bundle size limitation (250MB). The standard puppeteer package is too large. The solution involves two key packages:

Getting Started

We've created a ready-to-use template that handles all the configuration for you:

Deploy the Puppeteer on Vercel Template

This template comes pre-configured with all the necessary packages and settings to run Puppeteer on Vercel.

Related documentation