【问题标题】:Wrong module loaded on webpack federation with angular使用角度的 webpack 联合加载了错误的模块
【发布时间】:2021-03-12 16:12:34
【问题描述】:

我在端口 4200、4201 和 4202 上有 3 个应用程序。

在我的第一个应用程序(在 4200 上)上,我有一条通往其他应用程序的路由,该应用程序加载了它们的相应模块 ProfileModule,并且我正在基于此模块的导出组件创建组件。 请注意,我的应用具有 same 模块和导出的组件名称。

这很好用,但是由于某种原因,当我将路由从一个应用更改到另一个应用时,当组件已经加载一次时,webpack 会检索错误的模块。

我在这里做的是:

  1. 我正在路由到我的第二个应用程序(在 4201 上),它从 second-app 加载我的 ProfileModule
  2. 我正在路由到我的第三个应用程序(在 4202 上),它从 third-app 加载我的 ProfileModule
  3. 我要回到我的第二个应用程序,它会从 third-app 而不是 second-app 加载我的 ProfileModule

我猜这是由于模块名称,但如果它在不同的遥控器上不应该工作吗?

这是我获取模块的方式:

async function lookupExposedModule<T>(
  remoteName: string,
  exposedModule: string
): Promise<T> {
  // Initializes the share scope. This fills it with known provided modules from this build and all remotes
  await __webpack_init_sharing__("default");
  const container = window[remoteName] as Container; // or get the container somewhere else
  // Initialize the container, it may provide shared modules
  await container.init(__webpack_share_scopes__.default);
  const factory = await container.get(exposedModule);
  const Module = factory();
  return Module as T;
}

 

【问题讨论】:

    标签: javascript angular webpack


    【解决方案1】:

    我找到了解决方案here

    但就我而言,我的 webpack 配置中的不同遥控器具有相同的名称。

    【讨论】:

      猜你喜欢
      • 2022-06-25
      • 2021-09-08
      • 2018-12-03
      • 2021-09-17
      • 1970-01-01
      • 2020-10-07
      • 2020-02-27
      • 1970-01-01
      • 2022-07-15
      相关资源
      最近更新 更多