Webpack-关键依赖项:依赖项的请求是一个表达式 [英] Webpack - Critical dependency: the request of a dependency is an expression

查看:825
本文介绍了Webpack-关键依赖项:依赖项的请求是一个表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在准系统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调用中使用变量或表达式时(例如require(''+'nodent') epoberezkin / ajv / blob / c19c02aa045f8d8fe55852b4303899f82e6de381 / lib / async.js#L78 rel = noreferrer>这些行为 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.:


  1. 手动配置webpack导入所需的库并防止出现警告。

  2. hack.js 文件添加到我的项目中,该文件以某种方式覆盖了require调用。

  3. 升级我的库。 ajv-5.0.1-beta.3 有一个修复程序,可以消除警告。但是,如果要使用它,则必须等到它发布后,再等到 har-validator request 发布后续更新。如果可以强制 har-validator 使用Beta版本的 ajv ,那将解决我的问题。

  4. 其他

  1. Manually configure webpack to import the required libraries and prevent the warnings from occurring.
  2. Adding a hack.js file to my project that overrides the require calls in some way.
  3. 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 until har-validator and request release subsequent updates. If there is a way to force har-validator to use the beta version of ajv, that would solve my problem.
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆