question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dependencies that use require.ensure for backward compatibility cause warnings

See original GitHub issue

Importing 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:open
  • Created 5 years ago
  • Reactions:14
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

16reactions
localjocommented, Feb 14, 2019

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, but create-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.

9reactions
akuji1993commented, Apr 29, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ensuring backward compatibility in your applications - Medium
In software development, Backward compatibility is an important concept that ... It properly penalizes you for using too many dependencies.
Read more >
Ensuring backwards compatibility in distributed systems
If you're willing to put in the effort, achieving the three Ns is a great way to ensure backwards compatibility throughout a distributed...
Read more >
Package dependencies - Dart
You list only immediate dependencies—the software that your package uses directly. ... guaranteed to be backwards compatible with the specified version.
Read more >
Understanding dependency management with Node Modules
3. PATCH version when you make backwards compatible bug fixes. In the package.json , for each dependency you will see a corresponding semver...
Read more >
Contributing to the code base - Pandas
Optional dependencies. Backwards compatibility. Type hints. Style guidelines. pandas-specific types. Validating type hints. Testing type hints in code using ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found