Module Federation Support #33327
Replies: 64 comments 31 replies
-
Too hard |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
@rauchg @timneutkens @Timer @sokra I've updated the git issue, please let me know if there's any more information I can provide |
Beta Was this translation helpful? Give feedback.
-
Awesome! We're super excited about utilizing next+module federation to support microfront ends. And for what it's worth (seems like everyone has a different definition of micro front ends) here's the short definition of what we're wanting to do. We want to be to deploy our header/footer (layout) as a next app in vercel as well as 3-4 pages as separate next js apps in vercel. Ideally they're stitched together and client side routing is well supported (hopefully the nextjs libraries are shared between the apps). |
Beta Was this translation helpful? Give feedback.
-
This is more or less what im looking for as well, seamless page routing & component level ownership ☝️ |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
I've gotten Module Federation and Next routing to work. https://twitter.com/ScriptedAlchemy/status/1402319022331502592?s=20 This works client-side and probably could work server-side with some tweaks. You'll need a catchall page and the nextjs-mf plugin. Sample PR: module-federation/module-federation-examples#859 Likely ill move to a switch statement so I can take advantage of the Also will probably use a suspense implementation and if need be, write some utility which will be added to next-mf if a well-rounded solution looks cumbersome |
Beta Was this translation helpful? Give feedback.
-
As of today, I was able to use just the Module Federation plugin with next js. It appears that sharing works now, at least when it's in eager mode.
It's almost too good to be true. I'll perform some deeper tests tomorrow to confirm. |
Beta Was this translation helpful? Give feedback.
-
I’m having mixed results getting a good setup with Next.js 11 due to the issues @ScriptedAlchemy describes. Does anyone have an example project using Next.js 11 bi-directional CSR? |
Beta Was this translation helpful? Give feedback.
-
you have to use the next-mf plugin, which pretty much makes a third webpack build |
Beta Was this translation helpful? Give feedback.
-
it should be noted next-mf is not freely available - it is a paid plugin ! |
Beta Was this translation helpful? Give feedback.
-
🤔 @jonniedarko |
Beta Was this translation helpful? Give feedback.
-
@ecwyne https://github.com/module-federation/nextjs-mf is private repo now and
|
Beta Was this translation helpful? Give feedback.
-
Yep it's no longer a free plugin sorry fam but time is money 💰 v3 is on a paid registry, v2 is the last open release but doesn't work with newer versions of nextjs Next keeps breaking our support and keeping the project working for everyone requires non free engineering resources. All / many MF works moving forward will likely cater to paid packages as the OSS R&D is becoming too expensive. Times be changing. OSS was good while it lasted but funding is just too low. Can't invest $50k into a package just for the greater good anymore. Losses have to be recouped On a side note, funded research has allowed us to crack federated SSR in next.js. For those interested we do have a solid solution, so the model is advancing the ecosystem - despite it being an unpopular opinion. Either we stop coding all together or we find a way to fund our research 🔬 |
Beta Was this translation helpful? Give feedback.
-
As an architect at large enterprises, I work with systems at scale which often require distributing code. Module federation perfectly enables the ability to distribute code and I genuinely think Next.js will capture more of the enterprise market with MF support. Let’s make Next.js the react meta framework for enterprise level needs. This could be a massive point of differentiation from solutions like Remix. Thanks a bunch for your consideration. |
Beta Was this translation helpful? Give feedback.
-
@ScriptedAlchemy do you know if there are any plans to add an example of this to the Module Federation examples on GitHub and/or release a plugin to facilitate this? We already use Module Federation at work but are currently doing client-rendering which has obvious paint points. Ive wanted to move us to Next for some time now, but the ongoing lack of support for Module Federation means we would need to do some drastic reworking of our architecture that just wouldn't be worth it. If Remix looks winds up with more realistic Module Federation support in the nearer future, then that's ultimately the path for our company to head down. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
We appreciate everyone letting us know they’re looking for a solution here. However, we'd like to ask you to reserve comments for additional information to move this discussion forward. If you would like to show your support, please add a 👍 emoji on the initial comment instead. Thank you. |
Beta Was this translation helpful? Give feedback.
-
I've released a closed beta for federated SSR/CSR. This new plugin pretty much closes the gap between module federation and nextjs. Some concerns I'll be addressing.
I believe if I solve the security concerns of software streams, there should be no reason vercel cannot implement a total solution for federation. Stretch goal will be to run next from a Cloudflare worker only. Without SSG or ISR (proven possible, but on hold for now) This new plugin should effectively bring "first class" support to nextjs as I've already solved all quirks of using federation on next. If vercel has any concerns about federation beyond what I'm working on - I'd like to hear them. What concerns currently prevent you from supporting CSR? I understand SSR is more tricky but I am addressing those in a performant manner. Blast radius will not be a problem with encryption + true isolates. Performing load tests, it seems that federated next apps start and respond faster than non federated apps. Not sure how that's possible since streaming software should be slower than on disk reads. Update: its because less needs to be loaded into V8 compile cache during bootup In the future I'll be exploring "push not pull" for remote modules. That would stop and performance bottlenecks since software updates would be pushed into memory. That would also stop any stability concerns related to network failure since the broadcast would contain a buffer of all updates in its payload. (Possible but found other ways to improve perf) As always, I'd be happy to collaborate with vercel to solve this feature request once and for all. But I'd need a deeper collaboration effort with vercel to make meaningful progress. My nextjs solutions are commercial. Which locks out many users from being able to access federation. While I'm happy to collect a lot of money. I'd forgo the financial gains for native support - for the greater good of the community. |
Beta Was this translation helpful? Give feedback.
-
Hi to you all. Firstly thanks to @ScriptedAlchemy to his effort for Module Federation community. I also faced with problems when using NextJS app as a container app. You know, I had to give eager option (because sync load of app) then when I call a remote micro app (i.e react), shared modules are loading again. I followed a different way from your paid library. I used dynamic load technique for my remote library and it seems shared modules are not being fetched again and again now. They are being loaded only once. Also, I implemented full system as framework agnostic so you can use any framework as a remote app (angular, vue, react, svelte...). Also, I moved SSR logic to remote app part so now it can fully support SSR for any framework, too. It seems worked and I wanted to share my solution in here to help community. I wrote a medium blog post with example Github repo link. I told my approach with details. You can find detailed post in here: https://medium.com/@metinarslanturkk/how-i-implemented-dynamic-loaded-framework-agnostic-microfrontend-app-with-nextjs-and-react-which-620ff3df4298 And this is the example repo link: https://github.com/MetinArslanturk/microfrontend-nextjs-ssr Maybe, NextJS maintainers can follow a this like dynamic way for a workaround solution least in a minor version update. Everyone will be more happy with a built-in solution of course. Thanks, Metin |
Beta Was this translation helpful? Give feedback.
-
Chakra-UI Component issues (could relate to other shared dependencies also): Setup:
Issue: The shared dependencies in the HomePage app IS unnecessary but just adding it as a note to someone who crosses the same bridge. Maybe I'm doing something wrong? Also, Components (React.FunctionalComponents) seem to work perfectly with normal |
Beta Was this translation helpful? Give feedback.
-
Nextjs 12.X.X version support the module federation plugin? |
Beta Was this translation helpful? Give feedback.
-
Okay I've finally managed to enable full support for module federation on Next.js Without hacky workarounds. The latest release of nextjs-mf (v4.1.X) includes a /beta directory with new rewritten "NextFederationPlugin" Still undergoing tests - but everything I've tested so far works. Works just like module federation would on a normal application. No longer adds multiple build instances, uses a single compiler graph. Best news is the whole dependency sharing system now works perfectly, so "shared" doesn't cause strange issues or eager issues in next hosts. Anyways; Federation is now fully supported via nextjs-MF |
Beta Was this translation helpful? Give feedback.
-
In a shocking turn of events. I’ve released all my proprietary software as open source. https://twitter.com/scriptedalchemy/status/1567253027312246784?s=46&t=Sa4bhIDZI1i-q2GgYNGQuA My commercial next.js plugins are back on npm and SSR is supported out the box |
Beta Was this translation helpful? Give feedback.
-
This question is for Vercel team. Does Turbopack fill this gap on module federation? |
Beta Was this translation helpful? Give feedback.
-
Still waiting for getServerSideProps support, is there any news? |
Beta Was this translation helpful? Give feedback.
-
Whats the difference between nextjs zones vs nextjs module federation. I have main app and subapps which are hosted seperatly. But main app would use the subapps. Is this usecase possible with nextjs module federation? |
Beta Was this translation helpful? Give feedback.
-
I just read that the module federation team will likely not support nextjs in the future. |
Beta Was this translation helpful? Give feedback.
-
Feature request
@Timer @rauchg @timneutkens In order to stop my "Twitter Driven Development" (still love that quote) I have updated the description of this issue to hopefully help move this challenge forwards.
Is your feature request related to a problem? Please describe.
Support Module Federation ability to share vendor code, like react
Describe the solution you'd like
import(./bootstrap)
method in order to allow webpack to figure out if react exists already or if it needs to go and download the chunk. Ideally, there should be only one entrypoint, then whatever else needs to happen is done so via code splitting and async imports.shared: {import:'react',eager:true}
work - this would force react to be loaded upfront - however it seems that react is included multiple times in each entrypoint - causing various multiple copies of react issues. If eager worked, I could at least share react and force the remote to always use the hosts copy of react (I think) - this would / should be okay since next mostly requires us to be on a somewhat consistent version of react. Like next 11 will use v17, since all my apps use the latest nextjs, they will be compliment with a v17 version of react.The bare minimum to get this working client or server-side would be to have some flag that changes how the client entrypoint gets started. If the
client.js
looked like this https://github.com/module-federation/module-federation-examples/blob/master/bi-directional/app1/src/index.js then there's a high likelihood we could hold up the application until whatever shared modules with static imports were ready before hydration begins.Current Status
Vercel does not plan to support Module Federation, this discussion can likely be closed.
For those who need it:
https://app.privjs.com/buy/packageDetail?pkg=@module-federation/nextjs-mf (client side)
https://app.privjs.com/buy/packageDetail?pkg=@module-federation/nextjs-ssr (client and server-side support)
Related issue: #6040
Beta Was this translation helpful? Give feedback.
All reactions