【问题标题】:Webpack Module Federation Unsatisfied version 11.x.x of shared singleton module @angular/common (required ^7.2.0)Webpack Module Federation 共享单例模块 @angular/common 的不满意版本 11.x.x(需要 ^7.2.0)
【发布时间】:2021-05-22 08:09:33
【问题描述】:

我正在尝试让我相当复杂的单体应用程序与 Module Federation 一起使用。我的 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 错误,我被卡住了。我不知道如何找出哪个库可能会产生该错误。

【问题讨论】:

    标签: angular webpack webpack-5 webpack-module-federation


    【解决方案1】:

    您可能应该在每个共享项目上指定requiredVersion。如果你不指定它,webpack 将尝试不仅从你的主 package.json 中确定版本,而且从在你的 node_modules 中使用这些角度库的任何 npm 包中确定版本。

    当你导入一个使用 Angular 的第三方模块时,会发生什么情况,它会扫描 package.json 中的那个模块,并在此基础上添加另一个条目版本范围映射。这可能会导致不需要的行为,并且可能是您所看到的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 2012-10-31
      • 2021-04-04
      • 2022-08-18
      相关资源
      最近更新 更多