Deployment issue in viewing PDF using react-pdf

41 Views Asked by At

I used react-pdf to display a single-page PDF in a ReactJS application. It worked well during the development stage, but after deployment, it stopped working. It says, "Failed to load the pdf". What happened there, and how can I solve it? It would be a great help if you could assist me.

1

There are 1 best solutions below

1
Teju_tejaswini On

pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.js`;

//Make sure you use this in the deployment stage instead of 

pdfjs.GlobalWorkerOptions.workerSrc = new URL("pdfjs-dist/build/pdf.worker.min.js", import.meta.url).toString();