wojtekmaj / react-pdf

Display PDFs in your React app as easily as if they were images.
https://projects.wojtekmaj.pl/react-pdf
MIT License
9.33k stars 880 forks source link

react-scripts: 2.0.3 breaks dependencies in lib/display/api.js and build/pdf.js v3.0.5 #280

Closed lilcorey closed 4 years ago

lilcorey commented 6 years ago

Updating create-react-app to v2.0.3 has resulted in this node module to not load PDFs.

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

./node_modules/pdfjs-dist/lib/display/api.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

./node_modules/pdfjs-dist/lib/display/api.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

./node_modules/pdfjs-dist/lib/display/api.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

./node_modules/pdfjs-dist/build/pdf.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

./node_modules/pdfjs-dist/build/pdf.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

./node_modules/pdfjs-dist/lib/display/api.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

./node_modules/pdfjs-dist/build/pdf.js

Describe solutions you've tried

Deleting the module and reinstalling via npm install has resulted in the same issue.

Additional information

If applicable, add screenshots (preferably with browser console open) and files you have an issue with to help explain your problem.

Environment

Carlosf96 commented 4 years ago

Is this still being worked on or no? @wojtekmaj

tandat2209 commented 4 years ago

Any updates?

wojtekmaj commented 4 years ago

@bugzpodder Unfortunately pdfjs-dist 2.4.456 is a pre-release and we won't be updating to unstable dependency. I'm looking forward to Mozilla releasing a stable version, hopefully soon.

SamuelMS commented 4 years ago

@wojtekmaj How would you feel about pushing a new beta release with the new pdfjs-dist version so that we can do some testing on our end? i.e. v5.0.0-beta.3?

wojtekmaj commented 4 years ago

Sure thing, can be done - 5.0 will be out soon so we could advance the beta channel :)

hornetDC commented 4 years ago

I tried installing 5.0, still getting warnings.

SamuelMS commented 4 years ago

I tried installing 5.0, still getting warnings.

I'm pretty sure nothing has changed quite yet; if I'm interpreting what @wojtekmaj said earlier correctly, my guess is he'll release version 5.0 – which will ship with pdf.js 2.3.200 – as stable, and then create a new beta version – like 5.1.0-beta.1 – which will ship with pdf.js 2.4.456 (per #550).

aviggiano commented 4 years ago

I'm using the following postinstall script to handle this issue:

#!/usr/bin/env bash
# https://github.com/wojtekmaj/react-pdf/issues/280

set -eu

NL=$(grep -n 'var useRequireEnsure = false' ./node_modules/pdfjs-dist/build/pdf.js | awk -F: '{print $1}')
START=$((NL - 1))
END=$((START + 51))

sed -i.bak -e $START's/{/\/*{/' ./node_modules/pdfjs-dist/build/pdf.js
sed -i.bak -e $END's/}/}*\//' ./node_modules/pdfjs-dist/build/pdf.js
GabrielF9 commented 4 years ago

Hey guys, any updates on this problem? I managed to use the library following the tip from @mikemclin:

import {pdfjs, Document, Page} from 'react-pdf';

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

But I still get the warning:

./node_modules/pdfjs-dist/build/pdf.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Any current solution without using react-app-rewired?

gochi-dot commented 4 years ago

Hey @wojtekmaj . v2.4.456 is LTS now https://github.com/mozilla/pdf.js/releases/. Can we look into merging this PR https://github.com/wojtekmaj/react-pdf/pull/550 ?

FurkanToprak commented 4 years ago

Pinging this in hopes that this issue might be fixed soon? Any updates? @wojtekmaj

wojtekmaj commented 4 years ago

React-PDF 5.0.0-beta.4 is out with pdf.js 2.4.456 under the hood. Feedback from those previously affected by this bug is welcome :)

TimotheBarbe commented 4 years ago

I can confirm, with 5.0.0-beta.4 the error message is gone for me

BoazKG93 commented 4 years ago

error is gone with 5-beta.4

GabrielF9 commented 4 years ago

No errors in 5.0.0-beta.4. Waiting for the stable version.

PedroRuiz commented 4 years ago

I'm facing same problem: my dependencies are:

"dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.28",
    "@fortawesome/free-solid-svg-icons": "^5.13.0",
    "@fortawesome/react-fontawesome": "^0.1.10",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.19.2",
    "bootstrap": "^4.5.0",
    "bootswatch": "^4.5.0",
    "jsonwebtoken": "^8.5.1",
    "react": "^16.13.1",
    "react-bootstrap": "^1.0.1",
    "react-dom": "^16.13.1",
    "react-password-strength": "^2.4.0",
    "react-pdf": "^5.0.0-beta.4",
    "react-redux": "^7.2.0",
    "react-router": "^5.2.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "3.4.1",
    "react-toastify": "^6.0.5",
    "redux": "^4.0.5"
  },

I would thanks any help Best regards

GabrielF9 commented 4 years ago

@PedroRuiz just to confirm, you deleted the npm_modules folder? Before install again the packages?

SamuelMS commented 4 years ago

@wojtekmaj Hm. I get massive performance degradation and some odd behavior when upgrading from 5.0.0-beta.2 to 5.0.0-beta.4. We use the "standard" instructions to serve the PDF.js worker locally.

wojtekmaj commented 4 years ago

Please mind that this thread is for this specific error only. Please use #495 for general 5.0 beta discussion.

PedroRuiz commented 4 years ago

@GabrielF9 I did it.

GabrielF9 commented 4 years ago

@PedroRuiz Oh, I maked this and got all works fine. Can you share the part of code where you use the react-pdf?

PedroRuiz commented 4 years ago

@GabrielF9 I don't know why, it goes fine now. I apologize for inconvenience

GabrielF9 commented 4 years ago

@PedroRuiz happens hahahaha happy it worked

FurkanToprak commented 4 years ago

React-PDF 5.0.0-beta.4 is out with pdf.js 2.4.456 under the hood. Feedback from those previously affected by this bug is welcome :)

@wojtekmaj This fix works like a charm! Any insight on when it'll be in a stable version?

wojtekmaj commented 4 years ago

If not for the performance degradation it'd be already live. I don't think there will be any developer facing changes at this point though.

sivadass commented 4 years ago

Yes!!!, after upgrading to React-PDF 5.0.0-beta.4, the warning is gone!

kopecmi8 commented 4 years ago

It there any chance to resolve this error at 4.x version? I cannot use 5.x because of compatibility with IE11 :-/

wojtekmaj commented 4 years ago

There's no way. The first version pdfjs shipped with this issue was actually the one that already dropped IE11 support, which we noticed later.

dilemmawalker commented 3 years ago

I havent got any solution myself too & still stuck on the same prob.

wojtekmaj commented 3 years ago

As I said there's absolutely no way 4.x will have this issue fixed. Either upgrade to 5.x or live with it. Sorry.

janetlee commented 3 years ago

Bumped to 5.2.0 and still seeing this error message.

The irony here is that I don't even need this package. I don't display PDFs. The "standard" instructions don't work for me because I don't call on this package ever. It became a complete block when I moved to TS v4 coupled with another dependency upgrade I was testing out.

UPDATE: As advised, I fixed my TS config. If anyone is still getting these messages on Webpack 4, go back and walk through all your types and configuration. I added back a huge list of packages and it magically fixed itself.

"@babel/plugin-transform-runtime": "^7.13.8", <- installed it new
"@babel/runtime": "^7.13.8", <- installed it new
"@babel/runtime-corejs3": "^7.13.8", <- installed it new
"react-app-rewired": "^2.1.8", <- installed it new
"@babel/polyfill": "^7.12.1", <- installed it new
"@babel/preset-typescript": "^7.13.0", <- installed it new
"@types/jest": "^26.0.20", <- upgraded it
"@types/node": "^14.14.31", <- upgraded it
"@types/react": "^17.0.2", <- upgraded it
"@types/react-dom": "^17.0.1", <- upgraded it 
"babel-loader": "^8.2.2", <- upgraded it
"ts-import-plugin": "^1.6.7", <- installed it new
"typescript": "4.2.2",  <- upgraded it