You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hot reload causes the app to crash in the example repo when the remote component usage is removed and the change is reverted.
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `App`.
Comment or remove import and component usage in consumer/src/App.tsx
import"./App.css";// The remote component provided by federation_provider//import ProviderButton from "federation_provider/button";constApp=()=>{return(<divclassName="content"><h1>Rsbuild with React</h1><p>Start building amazing things with Rsbuild.</p><div>{/* <ProviderButton /> */}</div></div>);};exportdefaultApp;
Remove comment or discard changes
import"./App.css";// The remote component provided by federation_providerimportProviderButtonfrom"federation_provider/button";constApp=()=>{return(<divclassName="content"><h1>Rsbuild with React</h1><p>Start building amazing things with Rsbuild.</p><div><ProviderButton/</div></div>);};exportdefaultApp;
The text was updated successfully, but these errors were encountered:
This is the same behavior as webpack, I think this is part of the unresolved issues for module federation: not work perfectly with HMR.
In module federation, the remote modules rely on the loading of their corresponding chunk groups. When the chunk group is loaded asynchronously over the network, all the remote modules within that chunk group will be loaded together and combined into a promise. When this promise is resolved, both the loading of chunk group and the loading of remote modules will be completed.
However, in this case:
For the first load, the remote module will be successfully loaded into __webpack_modules__ along with the loading of the chunk group, which is as expected.
For the second load (with the import statement commented out), the remote module is removed from the module graph and also from __webpack_modules__, which is also as expected.
For the third load (after removing the comment), the update is sent to the runtime, which includes the remote module. But since the chunk group where the remote module is located has already been loaded, the remote module is not loaded into __webpack_modules__, resulting in the reported error.
Therefore, we need to provide a loading method for remote modules that does not rely on the loading of their corresponding chunk groups, or can re-trigger the loading of the chunk groups when they are re-introduced by HMR, to ensures that the remote modules are loaded into __webpack_modules__. cc @2heal1@ScriptedAlchemy
Version
Details
Hot reload causes the app to crash in the example repo when the remote component usage is removed and the change is reverted.
When app crashes
returns empty m.default instead of function
Issue mentioned also here module-federation/core#3465.
Reproduce link
https://github.com/rspack-contrib/rspack-examples/tree/main/rsbuild/module-federation-enhanced
Reproduce Steps
npm i
in both appsnpm dev
in both appslocalhost:2000
(consumer)import
and component usage inconsumer/src/App.tsx
The text was updated successfully, but these errors were encountered: