Webpack - 关键依赖:依赖的请求是一个表达式 [英] Webpack - Critical dependency: the request of a dependency is an expression
问题描述
在准系统 webpack 项目中导入 request
时,我收到三个警告消息.GitHub(运行 npm install
和npm start
).
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
).
关键依赖:一个依赖的请求是一个表达式
我怎样才能摆脱这个警告?
How can I get rid of this warning?
更多信息:
Webpack 尝试静态解析 require
调用以制作最小的包.当库在 require 调用中使用变量或表达式时(例如 这些行 ajv
),Webpack 无法静态解析它们并导入整个包.
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.:
- 手动配置 webpack 以导入所需的库并防止出现警告.
- 向我的项目添加一个
hack.js
文件,以某种方式覆盖 require 调用. - 升级我的图书馆.
ajv-5.0.1-beta.3
有一个使警告静音的修复程序.但是,如果我想使用它,我必须等到它发布,然后直到har-validator
和request
发布后续更新.如果有办法强制har-validator
使用ajv
的测试版,那将解决我的问题. - 其他
- 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
推荐答案
已解决 npm install request@2.79.0 --save
根据ajv
的作者的说法,这个问题可能会在几周后在最新版本的request
中得到解决.
According to the authors of ajv
, the issue will likely be resolved in the latest version of request
in a few weeks' time.
这篇关于Webpack - 关键依赖:依赖的请求是一个表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!