HeadlinesBriefing favicon HeadlinesBriefing.com

Fixing Chromium libnspr4.so Error on Vercel

DEV Community •
×

Deploying a Next.js app with Playwright and Chromium to Vercel often fails with a libnspr4.so missing library error. This occurs because Vercel's serverless environment lacks system libraries and has a read-only filesystem, unlike a local machine. The solution requires using the right packages and configuring environment variables correctly to bridge this gap.

The core issue is package choice and timing. Using the full playwright package exceeds Vercel's 50MB limit. Instead, use playwright-core (5MB) with @sparticuz/chromium (40MB). Crucially, the `AWS_LAMBDA_JS_RUNTIME` environment variable must be set in the Vercel Dashboard, not just in code, so it's available when modules load.

A critical missing piece is setting LD_LIBRARY_PATH to the executable directory before launching the browser. Without this, Chromium can't find its extracted libraries in `/tmp`. Additionally, disabling setGraphicsMode prevents freezing in GPU-less serverless environments. This three-part fix—correct packages, dashboard variables, and library path—solves the deployment puzzle.