angular - Webpack Module Federation 共享单例模块 @angular/common 的 11.xx 版本不满意(需要 ^7.2.0)
问题描述
我正试图让我相当复杂的单体应用程序与模块联盟一起工作。我的 webpack 配置看起来像这样
plugins: [
new ModuleFederationPlugin({
remotes: {
"mfe1": "mfe1@http://localhost:3000/remoteEntry.js",
},
shared: {
"@angular/core": { singleton: true, strictVersion: true },
"@angular/common": { singleton: true, strictVersion: true },
"@angular/router": { singleton: true, strictVersion: true },
...sharedMappings.getDescriptors()
}
}),
sharedMappings.getPlugin(),
],
在微前端方面共享是相同的。当我尝试运行应用程序时,我得到:
错误:共享单例模块 @angular/common 的 11.2.1 版本不满意(需要 ^7.2.0)
在此之前,我收到了类似的错误消息,但针对 angular/core。我通过重新运行纱线并根据不同的角度/核心版本修复库产生的所有警告来解决这个问题。
但是由于 fpr angular/common 错误,我被卡住了。我不知道如何找出哪个库可能会产生该错误。
解决方案
您可能应该requiredVersion
在每个共享项目上指定。如果你不指定它,webpack 将尝试不仅从你的主 package.json 中确定版本,而且从在你的 node_modules 中使用这些角度库的任何 npm 包中确定版本。
将会发生的情况是,每当您导入使用 Angular 的第三方模块时,它都会扫描 package.json 以查找该模块并基于此添加另一个条目版本范围映射。这可能会导致不需要的行为,并且可能是您所看到的原因。
推荐阅读
- r - 我的情节上应该有两条线
- php - json 解析 Stripe 发票响应
- android - 从活动android获取所有片段ViewPager中的所有视图值
- python-3.x - 无法使用刮板Python 3 selenium beautifulsoup4 urllib.request从pixiv下载图像
- python - Python 请求响应为空
- java - 在没有 web.xml 的情况下启用 ContainerRequestFilter
- python - 只有单线程使用多处理池使用 PySpark 执行并行 SQL 查询
- jquery - JQuery问题悬停在桌面上,点击手机和平板电脑
- vb.net - 在 Richtextbox 中保存图像时 OutOfMemory
- c++ - 为什么逻辑和顺序改变会给出不同的输出?