module-federation-examples
module-federation-examples copied to clipboard
Improve nextjs demo
Make nextjs demo app more like a real app
- [x] Add any Component library (used [email protected] for home, shop & 4.20.0 for checkout)
- [x] Add menu
- [x] Realize menu loading from another app
- [ ] Improve pages content
- [ ] Add images loading from other apps
- [ ] Add react-intl with translation loading
Known errors
- [ ]
localhost:3000->localhost:3000/testRemoteHookproducesShared module 'react' doesn't exist in shared scope default - [ ] menu does not restore back in host app.
localhost:3000/shop->/keepshopmenu but must showhomemenu
@ScriptedAlchemy could you please take a look at the problem Shared module 'react' doesn't exist in shared scope default
https://user-images.githubusercontent.com/1946920/183276433-016abb8a-20d3-4af7-b374-62038c49ef33.mov
If we reload the page, on first start they it works, but checkout app will get an error
https://user-images.githubusercontent.com/1946920/183276465-a13d6be7-55a8-45ec-876b-8b7a3d04840f.mov
hey yeah i can take a look
okay the sharing problem looks to be related to how next.js creates pages. The main webpack runtime expects to initialize all modules/remote improrts. Webpack container reference module id is in aother chunk/page, so in browser it logs a warning about init external failed. Then when you click on the page, the remote is found, loaded, and calls get - since init should have happened a startup.
This is a problem with multi entrypoint apps. But we can workaround it by manually re initialize it when its promise is resolving for the first time.
@nodkz is attempting to deploy a commit to the Module Federation Team on Vercel.
A member of the Team first needs to authorize it.
@ScriptedAlchemy I played with a workaround for several hours without luck. It seems that I'm not ready to solve such kinds of problems yet. I'll wait for a fix from you ;)
So I'll try to focus on other aspects: I found a new issue with remote assets and prepared a demo for this case. I already have a solution for it (fix url-loader & image-loader for sidecar), but I do not receive the invite to nexjs-mf repo to make a PR.
https://user-images.githubusercontent.com/1946920/184540052-6b00c54e-86d9-4f5f-830f-051cb37d6e84.mov
issueing a fix
@nodkz PR open for the plugin here: https://github.com/module-federation/nextjs-mf/pull/93