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

Webpack parser: {requireEnsure: false} not working #10253

Closed
julenr opened this issue Nov 14, 2018 · 12 comments
Closed

Webpack parser: {requireEnsure: false} not working #10253

julenr opened this issue Nov 14, 2018 · 12 comments

Comments

@julenr
Copy link

julenr commented Nov 14, 2018

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

@timvandermeij
Copy link
Contributor

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.

@Snuffleupagus
Copy link
Collaborator

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.

@timvandermeij
Copy link
Contributor

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

@localjo
Copy link

localjo commented Feb 13, 2019

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.

@localjo
Copy link

localjo commented Feb 13, 2019

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

@wpp
Copy link

wpp commented Feb 14, 2019

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?

@io-ma
Copy link

io-ma commented May 2, 2019

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.

@mikecousins
Copy link

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.

@mikecousins
Copy link

mikecousins commented Jun 19, 2019

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

@timvandermeij
Copy link
Contributor

timvandermeij commented Jun 19, 2019

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 #10253 (comment) would address the issue, then that is already tracked in a separate issue.

@io-ma
Copy link

io-ma commented Jun 20, 2019

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

@hugonasciutti
Copy link

For a temporary fix override the react-scripts rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants