diff --git a/next.config.ts b/next.config.ts index 2b4b4b2e..82a02ba2 100644 --- a/next.config.ts +++ b/next.config.ts @@ -23,8 +23,16 @@ const nextConfig: NextConfig = { // Keep pdfjs-dist out of the bundle. The legacy build references // @napi-rs/canvas at module load and breaks Vercel's bundling step. // Text extraction works in pure Node once DOM globals are stubbed at - // the call site (see extensions/general/invoice-inbox/lib/extract-invoice-fields.ts). + // module load (see extensions/general/invoice-inbox/lib/extract-invoice-fields.ts). serverExternalPackages: ['pdfjs-dist'], + // Force the pdfjs worker file into the function bundle. Next.js's tracer + // can't see it (loaded dynamically by name), so without this it's missing + // in /var/task and getDocument() fails with "Setting up fake worker failed". + // Scoped to the invoice-inbox sub-path — other extensions don't use pdfjs + // and shouldn't pay the ~1 MB worker cost. + outputFileTracingIncludes: { + '/api/extensions/ext/invoice-inbox/**': ['./node_modules/pdfjs-dist/legacy/build/pdf.worker.mjs'], + }, async redirects() { return [ {