(edited)
I came across this issue while trying to use puppeteer on Vercel.
Solution
What seems to work for now is explicitly defining the file tracings in next.config.ts and adding a fallback in the function logic.
1. Update next.config.ts
import type { NextConfig } from "next";
const nextConfig: NextConfig = { serverExternalPackages: ["@sparticuz/chromium", "puppeteer-core"], outputFileTracingIncludes: { "/api/print/route": ["node_modules/@sparticuz/chromium/bin/"], "/api/print": ["node_modules/@sparticuz/chromium/bin/"], },};
export default nextConfig;2. Implementation with Fallback
Explicitly defining the file tracings and also adding a fallback:
// Find the correct path for the chromium binarieslet executablePath = "";try { // Try to find it in the expected location for Vercel const binPath = path.join( process.cwd(), "node_modules/@sparticuz/chromium/bin", ); if (fs.existsSync(binPath)) { executablePath = await chromium.executablePath(binPath); } else { // Fallback to default which might work if not bundled executablePath = await chromium.executablePath(); }} catch (e) { console.error("Error resolving executable path:", e); // Last resort fallback executablePath = await chromium.executablePath();}