-
Notifications
You must be signed in to change notification settings - Fork 10.3k
2019 Recommended way to use pdf.worker.js with create-react-app #10813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't think anybody here is a React developer, so we can't help out with that, especially without a running example. There is a working example in https://github.com/mozilla/pdf.js/blob/master/examples/components/pageviewer.js#L25, so if that doesn't work for you then it's most likely something in It looks like wojtekmaj/react-pdf#291 is a similar problem. |
I have found a workaround for this problem. First, copy the pdf.worker.min.js to src/ folder and changed the cd src/
cp ../node_modules/pdfjs-dist/build/pdf.worker.min.js pdf.worker.min.data Then, in your javascript files, set the workerSrc like this. import workerURL from "./pdf.worker.min.data";
pdfjsLib.GlobalWorkerOptions.workerSrc = workerURL; This will trick the create-react-app to think pdf.worker.min.js as a data file and This way is simple and work with vanilla create-react-app without eject and Check the comment down below for a better, updated version of this hack. |
Thanks for sharing @tetrau , worked like a charm. |
Thanks for the idea @tetrau.
I guess the Node server in create-react-app does not know the mime type of .data files? Any clues how to fix this? |
@ubmarco I believe this problem is not caused by the node server or any server. It seems that Firefox blocks worker script requests with incorrect MIME i.e. non-javascript MIME. I have come up a new approach to solve this problem:
|
😆 wow having to do these gymnastics makes no sense, but thanks you just saved my day 👏 |
I've had problems that many had regarding using pdf.worker.js inside my react application (I build a wrapper on pdf.js for react).
I'm using Create React App, I tried many things from hosting from cloud:
PdfJsLib.GlobalWorkerOptions.workerSrc = PDFJS_WORKER_CLOUD_URL;
this works but I must make it work locally.
trying to use a local path does not work.
I read many issues and posts of stackoverflow, as well as did research but could not come with the right solution.
so my question is in 2019 - what is the recommended way to use pdf.js worker inside create-react-app
The text was updated successfully, but these errors were encountered: