module-federation-examples icon indicating copy to clipboard operation
module-federation-examples copied to clipboard

Multiple react versions runtime plugin example does not work with `loadRemote`

Open p12y opened this issue 1 year ago • 2 comments

Problem

Multiple react version runtime plugin example does not work with loadRemote, only import.

Example

https://github.com/module-federation/module-federation-examples/tree/master/runtime-plugins/multiple-react-versions

To recreate

In app1/App.js, update the lazy imports to use loadRemote instead of import:

+ import { loadRemote } from '@module-federation/enhanced/runtime';

- const ModernComponent = React.lazy(() => import('app2/ModernComponent'));
- const RemoteButton = React.lazy(() => import('app2/Button'));
+ const ModernComponent = React.lazy(() => loadRemote('app2/ModernComponent'));
+ const RemoteButton = React.lazy(() => loadRemote('app2/Button'));

Expected behaviour

The app should continue to work as expected

Actual behaviour

The app crashes with "ERROR Element type is invalid. Received a promise that resolves to: undefined. Lazy element type must resolve to a class or function."

image

Impact

The plugin approach to supporting multiple react versions does not work when using the runtime utils, which are needed when loading modules dynamically.

p12y avatar Sep 30 '24 05:09 p12y

Ill need to check this again, its been a while and we have since created the framework bridge capability.

https://module-federation.io/practice/bridge/index.html

ScriptedAlchemy avatar Oct 08 '24 19:10 ScriptedAlchemy

You also have to return an object with a default key. So loading remotely may not work without returning an object like {default: value}.

ScriptedAlchemy avatar Oct 23 '24 17:10 ScriptedAlchemy