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
Not working when using Browserify, fires a request to [object Object] #39
Comments
Hi! Thank you for your post and sorry for no reply. I dug into file history and I have not found any point in which we were using |
Hi @lorenzos, version 1.7.0 has just been released and it should fix your issue :) Let me know if it didn't. |
I wanted to use your component in my app, but I didn't manage to make it work (details below). After trying your sample directly from your repo, I noticed the issue comes from building my app using Browserify instead of Webpack. I can't get why Browserify fails, so I'm going to illustrate all my findings.
Sample built with Webpack
sample/index.html
works great.Sample built with Browserify
Need to edit
sample.jsx
, adding JSX extension inimport ReactPDF from '../src/react-pdf.jsx'
and removingimport './sample.less'
.sample/index.html
now does not work, in console I can see that a request is made tohttp://.../[object%20Object]
, which obviously fails. Searching your repo with this information, I found commit a3ab1c3: it says it fix my issue, but it does not. I tried to manually revert the commit, editingsrc/react-pdf.jsx
, removing that line and:Same error in console, but followed by three more lines:
Later I'll find that, in fact, the issue is somehow related to the worker.
"Older" version of your component works instead!
After many attempt to trace where the problem is, I gave up and tried
react-pdfjs
instead. This is another React component that uses PDF.js, so I was going to find out if the Browserify issue was with PDF.js itself, or not.To my surprise, this component worked well. Its README says that it is nothing but a port of your
react-pdf
! Comparing sources I concludedreact-pdfjs
is in fact based on a much older version ofreact-pdf
. So I went on in finding where the Browserify issue may arise.First thing I noticed is that the "old" code in
react-pdfjs
is not only missing the additional line from a3ab1c3, but it also requires'pdfjs-dist/build/pdf.combined'
instead of'pdfjs-dist/build/pdf'
plus'pdfjs-dist/build/pdf.worker.js'
. So I tried editing yoursrc/react-pdf.jsx
again:Finally:
And now your sample built with Browserify works! I tried rebuilding it again with Webpack, and it works too.
Questions
Unfortunately I didn't find through commits why your code is using
pdfjs-dist/build/pdf
instead ofpdf.combined
like the older port does, nor I found anything in existing issues related to the aforementioned commit a3ab1c3. So I'm asking you now, before proposing a change to your code.The only thing I found interesting is this issue on the port, which mentions
pdf.combined
and says it should not be used because it's like disabling worker, which anyway is what you already did in a3ab1c3.My goal is to make your component work well in my app, which I have to build with Browserify, so I'd be happy if we can find any different and more "explicit" solution. I'm not willing to use the old port in my app because it's missing features like
width
prop andonDocumentX
/onPageX
callbacks with detailed arguments.Hope I'd been helpful some way.
The text was updated successfully, but these errors were encountered: