当我开始使用带有服务器端渲染的 koa 的 webpack 来捆绑我的 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
我应该担心吗?
最佳答案
好吧,我几个小时前在 any-promise
中回答了这个问题Github 存储库。
所以我只是在这里复制答案:
这是因为 register.js
有 24 行动态导入:
var lib = require(implementation)
这意味着 webpack 无法静态解析 require 并导入整个包
你可以阅读 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
关于webpack - 我收到一个 webpack 警告严重依赖项 : the request of a dependency is an expression when use koa,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59235497/