Pdf.js: Webpack parser: {requireEnsure: false} not working

Created on 14 Nov 2018  路  12Comments  路  Source: mozilla/pdf.js

This is and issue with Webpack v4 when rule:

{
parser: { requireEnsure: false },
}

having this output:

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

Most helpful comment

What is the advantage of enabling that rule

It looks like create-react-app has set requireEnsure: false because it's not a standard language feature.

This leads to any create-react-app project that uses pdf.js to show 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

I don't understand this well enough to know if there's a way to include the fallback code that doesn't trigger the warning, but since it seems reasonable to include a fallback, I'll open an issue on the create-react-app repo too.

All 12 comments

What is the advantage of enabling that rule (since I don't think we enable it by default) and at which line does it go wrong? Is it in PDF.js source code or in generated bundle code? Please provide a bit more information and the contents of line 7873.

I don't think that Webpack setting is compatible with the fakeWorkerFilesLoader code that's necessary in some environments as a fallback when the user didn't configure workers properly, hence this issue is probably invalid from the PDF.js point of view.

Closing since I also don't think there is anything we can really do here.

What is the advantage of enabling that rule

It looks like create-react-app has set requireEnsure: false because it's not a standard language feature.

This leads to any create-react-app project that uses pdf.js to show 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

I don't understand this well enough to know if there's a way to include the fallback code that doesn't trigger the warning, but since it seems reasonable to include a fallback, I'll open an issue on the create-react-app repo too.

I'm not sure, but it looks like a possible solution to the fallback code would be to publish PDF.js as es6 modules and use something like rollup to ship the fallback code separately https://github.com/mozilla/pdf.js/issues/10317

I'm having trouble following the fakeWorkerFilesLoader code.

that's necessary in some environments as a fallback when the user didn't configure workers

@Snuffleupagus could you elaborate a bit on that? When will the fallback activate and how is the worker loaded in that case? What kind of environments are you referring to? Would it be possible to remove the fallback in favour of an error?

I have the exact problem, get the exact error from a plugin that is based on pdf.js (vue-pdf).
The error I get is:
WARNING in ./node_modules/pdfjs-dist/build/pdf.js 9818:60-67
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted.

I'm not sure, but it looks like a possible solution to the fallback code would be to publish PDF.js as es6 modules and use something like rollup to ship the fallback code separately #10317

This would be excellent. This warning is super annoying in any CRA project.

Is this never going to be fixed @timvandermeij? Just wondering if I should be waiting or moving.

It hasn't become clear that this is really something that needs to be fixed on the PDF.js side, and if so, what the alternatives for require.ensure are. We cannot provide support for "create-react-app", so it's probably best to file the issue in their tracker.

If https://github.com/mozilla/pdf.js/issues/10253#issuecomment-463377308 would address the issue, then that is already tracked in a separate issue.

@timvandermeij Hi, this happened to me in a Vue.js setup and I tried all plugins I could find. They were all based on pdf.js, and I got the same error:
WARNING in ./node_modules/pdfjs-dist/build/pdf.js 9818:60-67 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted.

For a temporary fix override the react-scripts rule.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kleins05 picture kleins05  路  3Comments

AlexP3 picture AlexP3  路  3Comments

anggikolo11 picture anggikolo11  路  3Comments

zerr0s picture zerr0s  路  3Comments

patelsumit5192 picture patelsumit5192  路  3Comments