Webpack-关键依赖项:依赖项的请求是一个表达式 [英] Webpack - Critical dependency: the request of a dependency is an expression
问题描述
在准系统webpack项目中导入请求
时,我收到三个警告消息。在 GitHub (运行 npm install
和 npm开始
)。
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
).
关键依赖项:依赖是一个表达式
我如何摆脱此警告?
更多信息:
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
使用Beta版本的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 $的作者c $ c>,这个问题很可能会在几周后用最新版本的
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屋!