ansu5555 / pdf-viewer-reactjs

A simple PDF viewer for React js
https://ansu5555.github.io/pdf-viewer-reactjs/
MIT License
139 stars 64 forks source link

[BUG] #81

Open hendras1722 opened 3 years ago

hendras1722 commented 3 years ago

Describe the bug How to fix this. when run react I found error. ./node_modules/pdfjs-dist/build/pdf.js 3454:145 Module parse failed: Unexpected token (3454:145) File was processed with these loaders:

How to Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots Please add screenshots to help explain your problem. image

PDF File Please attach the pdf file.

Details (please complete the following information):

Additional context Add any other context about the problem here.

mdsadiq commented 2 years ago

@hendras1722 can you share the version of library and version of its peer dependency pdfjs-dist

swingtechnologies commented 2 years ago

The below solution works for me First, install npm install npm-force-resolutions --save-dev

Then in package.json we need to override the pdfjs-dist version to previous working version like this

"dependencies": { "pdf-viewer-reactjs": "2.2.3", }. "scripts": { "preinstall": "npx npm-force-resolutions" }, "resolutions": { "pdfjs-dist": "2.6.347" } and in scripts section add new preinstall entry:

"preinstall": "npx npm-force-resolutions", now if you do npm install and run your application it should work. Hope it helps

The root cause of the problem is , though in the dependency package.json has version 2.6.347 for pdfjs-dist since ^ was there before the version number during npm install, it installs the most recent version of pdfjs-dist which is causing this problem.