vite-plugin-federation
vite-plugin-federation copied to clipboard
vite.config.ts同时配置remotes和exposes就会报错远程模块找不到。
Versions
- originjs: V ^1.1.7
- node: v14.17.3
- vue : ^3.2.37
这是我的配置:如果去掉expose,可以正常加载远程模块

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

What is Expected?
如果可以加载其他模块,加工之后在导出模块供其他使用就好了。我尝试webpack5的是可以的。
请提供一个复现工程。 Please provide a reproduction project.
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.
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.
declare module "router-remote/*"{}
大佬,你可能没明白我的问题,我说的不是编译报错,而是加载组件会报错找不到。
@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)
好的,我明白了。谢谢。
同时包含了 exposes 和 remotes 的项目,为什么不能支持 dev 模式呢?
由于vite的开发模式不能在运行时手动生成新的块,这导致远程不能生成remoteEntryjs文件。
Because vite's dev mode cannot manually generate new chunks during runtime, this causes remote to not generate remoteEntryjs files