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
Critical dependency: the request of a dependency is an expression
How can I get rid of this warning?
Webpack tries to resolve
require calls statically to make a minimal bundle. When a library uses variables or expressions in a require call (such as
require('' + 'nodent') in these lines of
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.jsfile to my project that overrides the require calls in some way.
- Upgrading my libraries.
ajv-5.0.1-beta.3has a fix that silences the warnings. However, if I want to use it, I have to wait until it is released, and then until
requestrelease subsequent updates. If there is a way to force
har-validatorto use the beta version of
ajv, that would solve my problem.
npm install [email protected] --save
According to the authors of
ajv, the issue will likely be resolved in the latest version of
request in a few weeks’ time.