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

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

问题描述

在准系统 webpack 项目中导入 request 时,我收到三个警告消息.GitHub(运行 npm installnpm 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.:

  1. 手动配置 webpack 以导入所需的库并防止出现警告.
  2. 向我的项目添加一个 hack.js 文件,以某种方式覆盖 require 调用.
  3. 升级我的图书馆.ajv-5.0.1-beta.3 有一个使警告静音的修复程序.但是,如果我想使用它,我必须等到它发布,然后直到har-validatorrequest发布后续更新.如果有办法强制 har-validator 使用 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天全站免登陆