Open MateoKruk opened 11 months ago
@MateoKruk did you manage to solve this? I have a similar situation but I'm using Vue, host is vite and remote is webpack
@echjordan0 nope, I stopped the migration for now
FWIW it turned out I had a naming mismatch because webpack allows prefixes on the remote url (e.g. prefix@localhost/remoreEntry.js
-- once I removed the prefix and changed all the names of the remote on the remote and host side it worked.
FWIW it turned out I had a naming mismatch because webpack allows prefixes on the remote url (e.g.
prefix@localhost/remoreEntry.js
-- once I removed the prefix and changed all the names of the remote on the remote and host side it worked.
you mean changing it in webpack from app2: app2@http://localhost:3000/remoteEntry.js
to app2: http://localhost:3000/remoteEntry.js
??
@sebastianestradaintcomex Here's what worked for us: HOST config (vite)
federation({
name: 'freshebt_vue',
remotes: {
freshcard_app: {
external: `${process.env.URL}/remoteEntry.js`,
format: 'var',
from: 'webpack',
},
},
shared: ['vue', 'vuetify'],
}),
REMOTE config (webpack)
config.plugin('module-federation').use(ModuleFederationPlugin, [
{
name: 'freshcard_app',
filename: 'remoteEntry.js',
shared: {
vue: {
singleton: true,
requiredVersion: dependencies.vue,
},
vuetify: {
requiredVersion: dependencies.vuetify,
},
},
exposes: { './microfrontend': './src/microfrontend.ts' },
},
]);
Import of webpack remote:
return (await import('freshcard_app/microfrontend')).default;
@MateoKruk I just finished migrating all of my project apps from Webpack to Vite, but when I deployed, I encountered this error. It feels like a waste of time; I wish I had known about this issue beforehand. did you find a solution?
@MateoKruk I just finished migrating all of my project apps from Webpack to Vite, but when I deployed, I encountered this error. It feels like a waste of time; I wish I had known about this issue beforehand. did you find a solution?
You should not have migrated to vite, even more so to use a feature that was implemented by default in webpack and this is just a library that tries to emulate its functionality but it is very unstable, if you are going to use ssr with module federation in vite let me tell you that you lost the time. Module Federation works best and with more stability in Webpack.
@sebastianestradaintcomex Here's what worked for us: HOST config (vite)
federation({ name: 'freshebt_vue', remotes: { freshcard_app: { external: `${process.env.URL}/remoteEntry.js`, format: 'var', from: 'webpack', }, }, shared: ['vue', 'vuetify'], }),
REMOTE config (webpack)
config.plugin('module-federation').use(ModuleFederationPlugin, [ { name: 'freshcard_app', filename: 'remoteEntry.js', shared: { vue: { singleton: true, requiredVersion: dependencies.vue, }, vuetify: { requiredVersion: dependencies.vuetify, }, }, exposes: { './microfrontend': './src/microfrontend.ts' }, }, ]);
Import of webpack remote:
return (await import('freshcard_app/microfrontend')).default;
We decided not to use Vite for projects with module federation due to its instability and difficulty with advanced configuration.
Versions
^1.3.1
^4.4.9
Reproduction
The setup I have today is the following:
react
+webpack
react
+webpack
I'm migrating the remote to
vite
and for now preserve the host as it is. I've done all the remote migration as it's working flawleslly by its own.The big problem I have is making the host work with the new remote. I'm getting the following error:
Basically
window[_scope]
isundefined
Host fetching remote code
I'm doing it this way because the
_url
is dynamic when deployed.Remote code
vite.config.js