Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react refresh runtime was loaded twice when trying to use @module-federation/bridge-react #164

Open
DanielSegal1 opened this issue Oct 18, 2024 · 7 comments

Comments

@DanielSegal1
Copy link

hi. I'm currently trying to build a vite host + remote with this plugin and @module-federation/bridge-react, so I can load a react 17 remote component into a react 18 host.
unfortunately I get the following error:

Uncaught Error: React refresh runtime was loaded twice. Maybe you forgot the base path?

the vite.config of the remote is:

defineConfig({
	plugins: [
		react(),
		federation({
            name: 'vite_guest_app',
			filename: 'remoteEntry.js',
            exposes: {
                './Button': './src/button/index.jsx'
            },
            // shared: ['react', 'react-dom']
        })
	],
	build: {
		modulePreload: false,
		target: 'esnext',
		minify: false,
		cssCodeSplit: false
	  }
})

and the one of the host is:

defineConfig({
    plugins: [
        react(),
        federation({
            name: 'host',
            remotes: {
                vite_guest_app: {
                    name: 'vite_guest_app',
                    type: 'module',
                    entry: 'http://localhost:5174/remoteEntry.js',

                },
                // webpack_guest_app: {
                //     external: 'http://localhost:8080/dist/remoteEntry.js',
                //     externalType: 'url',
                //     format: 'var',
                //     from: 'webpack'
                // }
            }
        })
    ],
    build: {
        modulePreload: false,
        target: 'chrome89',
        minify: false,
        cssCodeSplit: false
    }
})

the way I expose and consume the component is via @module-federation/bridge-react, and it looks like the following:
expose (at remote):

import { createBridgeComponent } from '@module-federation/bridge-react';
...
export default createBridgeComponent({
	rootComponent: Button
});

consume (at host):

import { loadRemote } from '@module-federation/enhanced/runtime'
import { createRemoteComponent } from '@module-federation/bridge-react';
...
const ConsumedButton = createRemoteComponent({
	loader: () => loadRemote('vite_guest_app/Button'),
	fallback: () => <div>error</div>,
	loading: <div>loading</div>,
});
...
<ConsumedButton />

any idea if I'm doing something wrong or if this plugin does not yet supports what I'm trying to achieve?

@gioboa
Copy link
Collaborator

gioboa commented Oct 18, 2024

Hi, thanks for the feedback, can you create a basic example to clone please? In this way we will tackle the problem easily

@DanielSegal1
Copy link
Author

uploaded the repo to dynamic-module-federation
you need to install node modules inside each of host and vite-guest dirs,
run (inside vite-guest): npm run build, npm run serve
run (inside host): npm run dev

@gioboa
Copy link
Collaborator

gioboa commented Oct 21, 2024

I'm looking at this issue and I have a different error though. I'm looking for a webpack bridge-react project to clone 👀 and migrate to Vite.

@DanielSegal1
Copy link
Author

what error are you getting?

@gioboa
Copy link
Collaborator

gioboa commented Oct 21, 2024

image

the remote has the right name though. So I looking forward to migrating a working webpack bridge-react project, but I can't find ones. Can you help me with that?

@DanielSegal1
Copy link
Author

I pushed a change to my repo in which I use import('vite_guest_app/Button') instead of loadRemote('vite_guest_app/Button')
and it seems to go back into the error which I described first.
Right now Im not so sure anymore that react-bridge is what I need. maybe you can advise something else for my use case (unrelated to this issue that may needs a solution anyway).
My use case is I want to load react version X component in a host with react version Y.
thanks

@nguyenbatranvan
Copy link

problem when using with vite-plugin-react-swc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants