I am getting three warning messages when importing request
in a barebone webpack project. A minimal example to reproduce the bug is available on GitHub (run npm install
and npm start
).
Critical dependency: the request of a dependency is an expression
How can I get rid of this warning?
More information:
Webpack tries to resolve require
calls statically to make a minimal bundle. When a library uses variables in a require call (such as these lines in ajv
), Webpack cannot resolve them statically and imports the entire package.
My rationale is that this dynamic import is not desirable in production, and code is best kept warning-free. That means I want any solution that resolves the problem. E.g.:
- Manually configure webpack to import the required libraries and prevent the warnings from occurring.
- Adding a
hack.js
file to my project that overrides the require calls in some way. - Upgrading my libraries.
ajv-5.0.1-beta.3
has a fix that silences the warnings. However, if I want to use it, I have to wait until it is released, and then untilhar-validator
andrequest
release subsequent updates. If there is a way to forcehar-validator
to use the beta version ofajv
, that would solve my problem. - Other