Dependencies that use require.ensure for backward compatibility cause warnings
See original GitHub issueImporting dependencies into an app created with create-react-app
that use require.ensure
as a fallback option causes the following warning in the console;
./node_modules/pdfjs-dist/build/pdf.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
This seems to be because the webpack settings in create-react-app
do not allow dependencies to use require.ensure
, but it seems that some libraries need to include this as a conditional fallback.
One possible solution might be to remove { parser: { requireEnsure: false } }
from the webpack configuration. I don’t see much context or discussion about why that rule is important other than that it’s not a standard language feature.
I can see the argument from both sides, both why create-react-app
would want to warn about this, and why another package might want to include it as a fallback. I don’t know the correct solution, but this causes noisy warnings in the console when starting an app that make it more difficult to focus on actionable warnings.
Maybe the correct solution is to allow the suppression of unwanted warnings in create-react-app
, but that seems to be a settled issue.
I’m open to any other workarounds or solutions.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:14
- Comments:12 (1 by maintainers)
From what I understand, the code using
require.ensure
in PDF.js is a fallback for non-webpack environments. In a webpack environment that code is irrelevant, butcreate-react-app
still warns about it because it doesn’t know from a static analysis that it’s irrelevant.@gaearon Do you have a specific recommendation for PDF.js contributors @timvandermeij or @Snuffleupagus on what would be the preferred way to support non-webpack users with this fallback? I’m sure this would be of general interest as well, since I’ve seen quite a few packages where people are reporting this warning.
I’d really like to see a solution to this issue as it’s currently holding us up from using react-pdf without having any alternative.