Puppeteer on Node 22.x: missing libnspr4.so

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

  1. Different Package Versions: I have tried multiple combinations of puppeteer-core and @sparticuz/chromium, including the latest versions (^24.x.x and ^123.x.x) as well as older, known-to-be-stable versions. The error changes slightly (e.g., missing libnss3.so) but always points to a missing shared library.

  2. Headless Modes: I have tried both the new ('new') and old (true) headless modes in Puppeteer.

  3. Increased Memory: I have increased the memory of the serverless function to 1024MB in vercel.json.

  4. 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

Hi, I’m encountering a similar error. Have you found a solution for it?

Edit: updated the puppeteer-core and @sparticuz/chromium to latest version has resolved the issue

"puppeteer-core": "^24.23.1",

"@sparticuz/chromium-min": "^141.0.0",

Also updated the Chromium executable path
// Get Chromium executable path from @sparticuz/chromium-min

const executablePath = await chromium.executablePath(‘https://github.com/Sparticuz/chromium/releases/download/v141.0.0/chromium-v141.0.0-pack.x64.tar’);

1 Like

I’m getting the same error, have you found a fix @boris-fami ? @adityarao-6293 solution is not working for me.

Vercel support gave me the solution :

Adding the environment variable AWS_LAMBDA_JS_RUNTIME=nodejs22.x to your project and redeploying it.

That worked perfect for me using @sparticuz/chromium instead of @sparticuz/chromium-min

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.