我收到一个webpack警告严重依赖:使用koa时,依赖的请求是一个表达式

问题描述 投票:0回答:1

当我启动webpack并使用带有服务器端渲染的koa绑定我的react应用程序时收到警告

WARNING in /app/node_modules/any-promise/register.js 24:14-37
[1] Critical dependency: the request of a dependency is an expression
[1]  @ /app/node_modules/any-promise/index.js
[1]  @ /app/node_modules/koa-compose/index.js
[1]  @ /app/node_modules/koa-convert/index.js
[1]  @ /app/node_modules/koa/lib/application.js
[1]  @ ./server/index.ts

我应该担心吗?

webpack koa
1个回答
1
投票

好吧,我几个小时前在any-promise github存储库中回答了这个问题:)

所以我只在这里复制答案:

发生这种情况是因为register.js在24行上具有动态导入:

var lib = require(implementation)

这意味着webpack无法静态解决需求并导入整个包

您可以阅读webpack文档的这一部分:https://webpack.js.org/guides/dependency-management/#require-with-expression

可以使用ContextReplacementPlugin解决,例如,您可以在Webpack中添加“假”配置以禁止显示此警告

plugins: [
    new ContextReplacementPlugin(/any-promise/)
]

而且我认为您不必担心,因为webpack只需要在服务器应用程序中使用“不必要的”程序包。

您也可以跟踪此问题:https://github.com/kevinbeaty/any-promise/issues/31

© www.soinside.com 2019 - 2024. All rights reserved.