当我启动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
我应该担心吗?
好吧,我几个小时前在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