vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

vite.config.ts同时配置remotes和exposes就会报错远程模块找不到。

Open SanMako opened this issue 3 years ago • 9 comments

Versions

  • originjs: V ^1.1.7
  • node: v14.17.3
  • vue : ^3.2.37

这是我的配置:如果去掉expose,可以正常加载远程模块 image

加上expose,就会报错,如下图: image

What is Expected?

如果可以加载其他模块,加工之后在导出模块供其他使用就好了。我尝试webpack5的是可以的。

SanMako avatar Jul 26 '22 07:07 SanMako

请提供一个复现工程。 Please provide a reproduction project.

flyfishzy avatar Jul 27 '22 08:07 flyfishzy

I'm having the same problem. Can't "expose" and "remote" at the same time in a vite config file in my host app. If I delete the "exposes" block, the import works fine again.

IsmaOrdas avatar Jul 27 '22 14:07 IsmaOrdas

请提供一个复现工程。 Please provide a reproduction project.

@flyfishzy 这是我的demo工程,辛苦大佬了,谢谢。 vite-mf-test.zip

SanMako avatar Jul 28 '22 04:07 SanMako

Add a declare module "router-remote/*"{} in your .d.ts file. Duplicate of https://github.com/originjs/vite-plugin-federation/issues/129. Maybe we need a typescript example project.

flyfishzy avatar Aug 01 '22 13:08 flyfishzy

declare module "router-remote/*"{}

大佬,你可能没明白我的问题,我说的不是编译报错,而是加载组件会报错找不到。

SanMako avatar Aug 03 '22 01:08 SanMako

@SanMako 我尝试更改一下你的项目,这里是git diff的截图 I would try to change your project, here is a screenshot of git diff

图片

在我这里是可以成功编译和运行的 It compiles and runs successfully in my case

图片

我猜测你使用了dev模式启动了其中的项目,在你的项目里只能使用build&preview模式启动,因为只有完全的host端才可以使用dev模式启动(app-one和app-two都包含了exposes,只包含remotes配置的才可以使用dev) I guess you used dev mode to start one of the projects, you can only use build&preview mode to start in your project, because only the full host side can use dev mode to start (app-one and app-two both contain exposes, only those containing remotes configuration can use dev)

Jiannan-dev avatar Aug 03 '22 06:08 Jiannan-dev

好的,我明白了。谢谢。

SanMako avatar Aug 03 '22 10:08 SanMako

同时包含了 exposes 和 remotes 的项目,为什么不能支持 dev 模式呢?

iotopo avatar Aug 08 '22 01:08 iotopo

由于vite的开发模式不能在运行时手动生成新的块,这导致远程不能生成remoteEntryjs文件。

Because vite's dev mode cannot manually generate new chunks during runtime, this causes remote to not generate remoteEntryjs files

Jiannan-dev avatar Aug 11 '22 02:08 Jiannan-dev