0

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
  • 1
    Without the code I don't think I can provide more in-sign. But the first thing that comes into mind is that probably the file gets blocked because of CORS or something around that, since as you mentioned it works in your dev build. Commented Mar 26, 2024 at 8:42

1 Answer 1

0

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();

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.