I am building a web app where you can upload and chat with your pdf. I am using pdfjs-dist (module version 2.16.105) to read the pdf. Everything works fine on my localhost, but after deploying it on Vercel, I am getting this error -
Setting up fake worker failed: "Cannot find module './pdf.worker.js'
Require stack:
/var/task/node_modules/pdfjs-dist/legacy/build/pdf.js
/var/task/.next/server/pages/api/process.js
/var/task/node_modules/next/dist/server/next-server.js
/var/task/___next_launcher.cjs".
error image
This is the link to my web app - https://publang.vercel.app/
You can upload a pdf and then when you click on process file, you get the above mentioned error.
I was using Typescript and I did deployed the next js app on vercel. But i did encounter the same error. It got fixed by following code.
const pdfjs = await import("pdfjs-dist/legacy/build/pdf.js");
pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/legacy/build/pdf.worker.js',import.meta.url,).toString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With