Fix PDF export on Vercel via serverless Chromium fallback#11
Merged
Conversation
The full puppeteer package bundles ~170 MB of Chromium, which exceeds Vercel's 50 MB function size limit and caused PDF export to fail with "Serverfehler" (#9). The launcher now auto-detects serverless runtimes (VERCEL / AWS_LAMBDA_FUNCTION_NAME) and falls back to puppeteer-core + @sparticuz/chromium, while Node hosts / Docker / VPS deployments keep the full puppeteer path unchanged. Infra stays single-service; an external renderer (see #7) is not needed. Also extracts the render-target URL resolution and adds unit tests + a tiered manual smoke-test checklist for future regressions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
These were staged during the initial fix commit but ended up missing from the committed package.json while present in pnpm-lock.yaml, causing CI to fail with ERR_PNPM_OUTDATED_LOCKFILE. Restores parity so `pnpm install --frozen-lockfile` works. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
JakeLeoDev
approved these changes
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9.
Closes #7 as duplicate — both issues describe the same root cause (Puppeteer's bundled Chromium not working on Vercel). This PR fixes it in-process instead of outsourcing rendering.
Summary
VERCEL/AWS_LAMBDA_FUNCTION_NAME) and fall back topuppeteer-core+@sparticuz/chromium; non-serverless paths (Node / Docker / VPS / Railway / Fly.io) keep the fullpuppeteerbundle unchanged.maxDuration = 60on the PDF route (Vercel Pro / Fluid Compute; Hobby's 10 s is too short).INTERNAL_APP_URL→VERCEL_URL→NEXT_PUBLIC_APP_URL→localhost, and TLS is only stripped for real localhost hostnames (not for public Vercel URLs).Root cause (covers #9 and #7)
puppeteerbundles ~170 MB of Chromium. Vercel's function size limit is 50 MB unzipped, so the binary was missing at runtime and every PDF request failed withServerfehler — bitte versuchen Sie es später erneut.Serverfehleron Export).Both are resolved by swapping in
@sparticuz/chromiumwhen the process detects a serverless runtime — no external service needed.Why this approach (vs. an external renderer as proposed in #7)
Discussed with @JakeLeoDev in-thread — the project's value proposition is a slim stack (Next.js + Supabase). Spinning up a Gotenberg/Browserless service just for PDF is infrastructure bloat at Proposit's target usage volume.
@sparticuz/chromiumstays single-service, fixes Vercel, and keeps the render target as the app's own/proposals/[id]/pdfpage — so PDF output still matches the on-screen preview byte-for-byte.The external-renderer path from #7 remains reasonable for high-volume / multi-tenant-scale deployments and could be added later as an opt-in (
PDF_RENDERER_URL) without disturbing the default. If / when that need materialises, a new issue should be filed with concrete scale numbers.What changed
lib/pdf/launch.ts(new) —launchBrowser(),resolveInternalAppUrl(),isServerlessRuntime().app/api/proposals/[id]/pdf/route.ts— uses the launcher +maxDuration = 60.next.config.ts—serverExternalPackages: ['puppeteer', 'puppeteer-core', '@sparticuz/chromium'].lib/pdf/__tests__/launch.test.ts(new) — 11 unit tests covering env precedence + runtime branch selection.context/pdf-export-testing.md(new) — manual smoke-test checklist per rendering tier..env.example(new) — was referenced in CLAUDE.md but missing from the repo;.gitignoreamended with!.env.example.README.md/CLAUDE.md— deployment + convention notes.vitestsetup (config + scripts) that the new unit tests need.Test plan
@JakeLeoDev — bitte um Testing. Die Tiers sind in
context/pdf-export-testing.mddokumentiert. Kurzform:pnpm install && pnpm test lib/pdf— 11 unit tests should passpnpm build— should succeed without Chromium/bundler warningspnpm dev, open an existing proposal, Export PDF → downloads in ~3-8 s, matches on-screen previewServerfehler[PDF] requestfailed/[PDF] response >=400in Vercel function logs during the successful exportCo-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com