Next.js Discord

Discord Forum

Vercel: Issue with pdfjs-dist

Unanswered
Samir posted this in #help-forum
Open in Discord
I've been trying to read content of pdf. It works fine on my pc but on vercel it says Setting up fake worker failed: "Cannot find module '/var/task/node_modules/pdf-text-reader/node_modules/pdfjs-dist/build/pdf.worker.mjs' imported from /var/task/node_modules/pdf-text-reader/node_modules/pdfjs-dist/build/pdf.mjs"

I'm using pdf-text-reader package which uses pdfjs-dist underhood.

8 Replies

try installing pdfjs-dist too
I did, still the same issue
And this process on happening on the server side
try dynamic importing the component with ssr: false, because this component can't be on the server
I mean its running for api route
After adding parallelism, I'm having the issue. I even tried setting max op at a time to 3 and still same issue
everything just works fine on my pc
I fixed the issue by downgrading to pdfjs-dist@4.8.69

import * as pdfjsLib from "pdfjs-dist/build/pdf.min.mjs";

export async function extractPagesFromPDF(data: ArrayBuffer): Promise<Page[]> {
  // @ts-ignore
  await import("pdfjs-dist/build/pdf.worker.min.mjs");
  
}