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 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 untilhar-validatorandrequestrelease subsequent updates. If there is a way to forcehar-validatorto use the beta version ofajv, that would solve my problem. - Other
Solved with npm install request@2.79.0 --save
According to the authors of ajv, the issue will likely be resolved in the latest version of request in a few weeks' time.
Replace this
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
helpers.root('./src'), // location of your src
{} // a map of your routes
),
with this-
new webpack.ContextReplacementPlugin( /(.+)?angular(\\|\/)core(.+)?/, root('./src'), {} )
来源:https://stackoverflow.com/questions/42908116/webpack-critical-dependency-the-request-of-a-dependency-is-an-expression