Hello Vercel Community,
I’m trying to use Puppeteer in a serverless function on Vercel to scrape web content, but I’m running into an issue with a missing shared library. I’ve tried several solutions but seem to be stuck.
The Problem
My serverless function is running on the Node.js 22.x runtime. When it attempts to launch a Chromium instance using Puppeteer, the function fails with the following error:
/tmp/chromium: error while loading shared libraries: libnspr4.so: cannot open shared object file: No such file or directory
This suggests that the nspr package is not available in the standard Node.js 22.x execution environment.
My Setup
I am using puppeteer-core with @sparticuz/chromium as recommended for serverless environments. Here is a snippet of my launch configuration in my api/scrape.ts file:
import chromium from '@sparticuz/chromium';
import puppeteer from 'puppeteer-core';
// ...
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: 'new', // Also tried with chromium.headless
});
What I’ve Tried So Far
-
Different Package Versions: I have tried multiple combinations of
puppeteer-coreand@sparticuz/chromium, including the latest versions (^24.x.xand^123.x.x) as well as older, known-to-be-stable versions. The error changes slightly (e.g., missinglibnss3.so) but always points to a missing shared library. -
Headless Modes: I have tried both the new (
'new') and old (true) headless modes in Puppeteer. -
Increased Memory: I have increased the memory of the serverless function to 1024MB in
vercel.json. -
Node.js Version: I am on Node.js 22.x, as required by Vercel.
My Question
Has anyone else encountered this issue with the Node.js 22.x runtime on Vercel? Is there a recommended way to run Puppeteer in this environment, or a known workaround to include the necessary shared libraries like libnspr4.so?
Any help or insights would be greatly appreciated