当我开始使用带有服务器端渲染的 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
Run Code Online (Sandbox Code Playgroud)
我应该担心吗?
好吧,我几个小时前在any-promiseGithub 存储库中回答了这个问题。
所以我只是在这里复制答案:
发生这种情况是因为register.js在 24 行上有一个动态导入:
var lib = require(implementation)
Run Code Online (Sandbox Code Playgroud)
这意味着 webpack 无法静态解析 require 并导入整个包
你可以阅读 webpack 文档的这一部分:https ://webpack.js.org/guides/dependency-management/#require-with-expression
可以使用 解决它ContextReplacementPlugin,例如,您可以在 webpack 中添加“假”配置以抑制此警告
plugins: [
new ContextReplacementPlugin(/any-promise/)
]
Run Code Online (Sandbox Code Playgroud)
而且我认为您不必担心,因为 webpack 只需要将“不必要的”包放入您的服务器应用程序中。
您还可以跟踪此问题:https : //github.com/kevinbeaty/any-promise/issues/31
| 归档时间: |
|
| 查看次数: |
6340 次 |
| 最近记录: |