Skip to content
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

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

Closed
lilcorey opened this issue Oct 2, 2018 · 81 comments
Assignees
Labels
bug Something isn't working

Comments

@lilcorey
Copy link

lilcorey commented Oct 2, 2018

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

  • Browser (if applicable) [e.g. Chrome 57, Firefox 59]: N/A
  • React-PDF version [e.g. 3.0.4]: 3.0.5
  • React version [e.g. 16.3.0]: 16.4.1
  • Webpack version (if applicable) [e.g. 4.16.2]: 4.19.1
  • React scripts: 2.0.3
@wojtekmaj
Copy link
Owner

wojtekmaj commented Oct 4, 2018

Hello,
thanks. This should probably be reported to mozilla/pdf.js.

Webpack 4 is not supported officially at the moment, but will be in version 4 - have you tried using it instead by installing react-pdf@next?

@wojtekmaj wojtekmaj reopened this Oct 4, 2018
@wojtekmaj wojtekmaj self-assigned this Oct 4, 2018
@wojtekmaj wojtekmaj added the question Further information is requested label Oct 4, 2018
@chiragv508
Copy link

yes.it's incompatile with react-script-2

@wojtekmaj
Copy link
Owner

Check your console and look if your error is mentioned in Known issues. I just updated it while I was handling a similar issue.

@wojtekmaj
Copy link
Owner

Create React App is not yet compatible with worker-loader. It will be once facebook/create-react-app#3934 gets merged. For now, users of Create React App both 1.x and 2.x need to use generic solution.

@tzieleniewski
Copy link

@wojtekmaj May you confirm that generic solution means

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

and manual copy of the pdf.worker.js file from pdfjs-dist/build is project's output folder.

@wojtekmaj
Copy link
Owner

wojtekmaj commented Nov 19, 2018

Yes, that is the generic solution @tzieleniewski. You can also use CopyWebpackPlugin to do it with every build.

@Krivega
Copy link

Krivega commented Nov 29, 2018

@tzieleniewski @wojtekmaj
small automation: add "postinstall": "cp node_modules/pdfjs-dist/build/pdf.worker.min.js public/pdf.worker.min.js" to the scripts section in the package.json

@mikemclin
Copy link

mikemclin commented Dec 12, 2018

So to confirm, there is a working solution, but we're still unable to get rid of the Critical dependency: require function is used in a way in which dependencies cannot be statically extracted warning.

  • react-scripts 2.1.1
  • react-pdf 4.0.0
  • pdfjs-dist 2.0.943
  • webpack 4.19.1

@wojtekmaj
Copy link
Owner

Correct. I'll be working with Mozilla to getting that fixed once for good, but it will take some time.

@adnux
Copy link

adnux commented Dec 28, 2018

Correct. I'll be working with Mozilla to getting that fixed once for good, but it will take some time.

Hi!
Any updates on this?
I was trying to make "react-pdf" 4.0.0 to work with "react-scripts" v2.1.2 but still having some trouble:

  • Setting up fake worker failed: "Cannot read property 'WorkerMessageHandler' of undefined".

@mikemclin
Copy link

@adnux If you are upgrading, then your old implementation will not work. You will need to follow the Browserify & Others documentation.

Your imports/setup will probably look something like this...

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

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

@rovaniemi
Copy link

rovaniemi commented Feb 6, 2019

Hi!
Any updates?

I still get this error message.

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

Environment

  • Browser (if applicable) [e.g. Chrome 57, Firefox 59]: N/A
  • React-PDF version [e.g. 3.0.4]: 3.0.5 and also 4.0.2
  • React version [e.g. 16.3.0]: 16.8.0
  • React scripts: 2.1.3

@localjo
Copy link

localjo commented Feb 13, 2019

This warning seems to be related to Mozilla's PDF.js using require.ensure for fallback purposes, but create-react-app's webpack configuration warning about it since it's a non-standard language feature. I'm not sure what the correct solution is, but I've opened an issue on the create-react-app repo for discussion, and this issue on the PDF.js repo might also be relevant.

@varunpatro
Copy link

Is there any temporary fix to this problem at present?

@maciejmatu
Copy link

@varunpatro I am using craco to allow modification of CRA webpack config, and I remove the { parser: { requireEnsure: false } } rule. My issue was that the CI server would treat the warning as an error and I wasn't able to deploy the project. Remember it's a hacky temporary fix 😄

Here is craco.config.js code I use, maybe it will help someone.

const { isEqual } = require("lodash");

module.exports = {
  webpack: {
    configure(webpackConfig) {
      const updatedRules = webpackConfig.module.rules.filter(
        rule => !isEqual(rule, { parser: { requireEnsure: false } })
      );
      webpackConfig.module.rules = updatedRules;

      return webpackConfig;
    }
  }
};

@softwareplumber
Copy link

Same CI issue as @maciejmatu - I will look into his hack but the person who fixes this properly will have my undying gratitude.

@OnimeNoKyo
Copy link

Same CI issue as @MaciejMat

@mbaric1
Copy link

mbaric1 commented Apr 1, 2019

Compiled with warnings.

./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/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

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

Environment

  • react-scripts: "^2.1.1"
  • react-pdf: "^4.0.5"
  • react: "^16.6.3"
  • typescript: "^3.2.1",

@maciejmatu Hack works. But are there any other solutions or updates on this issue?

Thanks!

@rsmything
Copy link

Hello, the same issue
[email protected]
[email protected]
[email protected]

any updates?

@wojtekmaj wojtekmaj added the help wanted Extra attention is needed label Apr 11, 2019
@akuji1993
Copy link

akuji1993 commented Apr 29, 2019

This is holding us back actually using your library. It means that in most cases, the CI software will not let this through, as warnings are interpreted as errors. And for a lot of people, @maciejmatu's solution won't work because we don't want to work around CRA default scripts. So this means either dropping react-pdf or finding some kind of a solution.. Which neither really is to my liking :/

@mikemclin
Copy link

@akuji1993 You can also disable warnings in your CI (which cause broken builds) by doing something like this: CI=false npm run build.

@simoneb
Copy link

simoneb commented Apr 29, 2019

@mikemclin that's generally not a good idea because quite a few tools behave differently when running under CI

@mikemclin
Copy link

@simoneb you only need to turn the CI off when running your Create React App build command. You could keep it on for other build steps (testing, deploy, etc).

@gabsf-dev
Copy link

gabsf-dev commented Jun 1, 2020

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
Copy link

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

@FurkanToprak
Copy link

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

@wojtekmaj
Copy link
Owner

wojtekmaj commented Jun 9, 2020

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
Copy link

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

@BoazKG93
Copy link

error is gone with 5-beta.4

@wojtekmaj wojtekmaj removed the help wanted Extra attention is needed label Jun 11, 2020
@gabsf-dev
Copy link

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

@PedroRuiz
Copy link

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

@gabsf-dev
Copy link

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

@SamuelMS
Copy link

@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
Copy link
Owner

wojtekmaj commented Jun 18, 2020

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

@PedroRuiz
Copy link

@GabrielF9 I did it.

@gabsf-dev
Copy link

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

@PedroRuiz
Copy link

PedroRuiz commented Jun 26, 2020

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

@gabsf-dev
Copy link

@PedroRuiz happens hahahaha happy it worked

@FurkanToprak
Copy link

FurkanToprak commented Jul 4, 2020

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
Copy link
Owner

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
Copy link

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

@kopecmi8
Copy link

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

@wojtekmaj
Copy link
Owner

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
Copy link

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

@wojtekmaj
Copy link
Owner

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
Copy link

janetlee commented Feb 25, 2021

Bumped to 5.2.0 and still seeing this error message.

  • "react-pdf": "5.2.0",
  • "react-scripts": "^3.4.3",
  • "react": "16.13.0",
  • "typescript": "4.1.5",
  • "webpack": "^4.44.2"

Screen Shot 2021-02-25 at 3 14 23 PM

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

eventualbuddha added a commit to votingworks/vxsuite that referenced this issue Mar 15, 2022
The React app build failed with the previous version of `pdfjs-dist` due to a dynamic require. See wojtekmaj/react-pdf#280 (comment). This commit updates it to the first version that fixed the problem (I've had issues with newer versions of `pdfjs-dist`, though we should try again at some point).
eventualbuddha added a commit to votingworks/vxsuite that referenced this issue Mar 15, 2022
The React app build failed with the previous version of `pdfjs-dist` due to a dynamic require. See wojtekmaj/react-pdf#280 (comment). This commit updates it to the first version that fixed the problem (I've had issues with newer versions of `pdfjs-dist`, though we should try again at some point).
eventualbuddha added a commit to votingworks/vxsuite that referenced this issue Mar 16, 2022
The React app build failed with the previous version of `pdfjs-dist` due to a dynamic require. See wojtekmaj/react-pdf#280 (comment). This commit updates it to the first version that fixed the problem (I've had issues with newer versions of `pdfjs-dist`, though we should try again at some point).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests