priyanshujain / react-pdf-preview

PDF preview compoent using pdfJS
MIT License
8 stars 2 forks source link

Module parse failed #1

Open DimaSmartBID opened 6 years ago

DimaSmartBID commented 6 years ago

Hi, I receive this error: Module parse failed: Unexpected token (5:2) You may need an appropriate loader to handle this file type.

How can I fix this?

danielrfranco commented 5 years ago

Same here...

priyanshujain commented 5 years ago

Hi @DimaSmartBID and @danielrfranco Thanks for pointing it out. I'm not super active on my projects for last couple of months. I'll look into the issue.

scailbc commented 5 years ago

According to this stackoverflow answer the error is related to babel.

I tried to copy the 3 files inside the src folder into my project and the error doesn't appear.

I solved it by copying all the files into my project with the following corrections:

PDFJS.GlobalWorkerOptions.workerSrc = //cdnjs.cloudflare.com/ajax/libs/pdf.js/${PDFJS.version}/pdf.worker.js;

class PDF extends Component {


- inside `pdf.js` change `pdf.pdfInfo` into `pdf._pdfInfo`
- inside `pdf.js` change `Array(...{ length: numPages })` into `Array.from({ length: numPages) })`

It doesn't fix the library, but at least you can show the pages.
Hope this helps.