Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"setting up fake worker failed cannot find module './pdf.worker.js' " error after Vercel deployment

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.

like image 965
Manas Kala Avatar asked Dec 11 '25 11:12

Manas Kala


1 Answers

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();
like image 57
Vsmadak Attar Avatar answered Dec 14 '25 03:12

Vsmadak Attar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!