create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Webpack 5 support (module federation)

Open bradydowling opened this issue 6 years ago • 65 comments

Is your proposal related to a problem?

It would be great to be able to use federated modules in Webpack with a CRA application.

Describe the solution you'd like

Provide support for Webpack 5 by upgrading the default Webpack version to 5. This was previously requested (https://github.com/facebook/create-react-app/issues/6081) but closed because Webpack 5 wasn't in beta at the time. It is now in beta and has had several releases.

Describe alternatives you've considered

You could also allow an opt-in to using Webpack 5 (just like Next.js does) when users initially run CRA from the command-line.

bradydowling avatar Aug 19 '20 17:08 bradydowling

For those following this issue, @petetnt mentioned in https://github.com/facebook/create-react-app/issues/9678 that "Webpack 5 is probably landing in [email protected]. if all the bugs and issues are fixed before that." Not sure what the typical release schedule is for CRA, I'm guessing there's info about that somewhere that I just haven't found yet.

bradydowling avatar Sep 24 '20 18:09 bradydowling

4.1 was mentioned but it's not assigned to the milestone yet - but I guess the big question would be how to configure the modules for module federation in CRA?

raix avatar Oct 09 '20 10:10 raix

Webpack 5 is released https://webpack.js.org/blog/2020-10-10-webpack-5-release/

shospodarets avatar Oct 10 '20 22:10 shospodarets

To provide more context to the discussion (since module federation is new, so I believe not everyone know what it means), I think module federation support can be further broken down into two parts:

  • consuming federated modules
  • exposing modules to be consumed remotely

Having both would be ideal, but support for only one is better than none.

malcolm-kee avatar Oct 25 '20 05:10 malcolm-kee

Also, I'm not very optimistic module federation will be supported by CRA, because CRA guiding principle has been "rather sacrifice functionality than introducing configuration". Due to the fact that module federation requires configuration (there is no sensible default) and no existing configuration files (e.g. jsconfig.json / tsconfig.json) supports it yet, I can't see anyway module federation can land in CRA in near future.

A more probable direction will be CRA supports webpack 5, and those of us need module federation will fork it and introducing our own configuration convention.

malcolm-kee avatar Oct 25 '20 05:10 malcolm-kee

Due to the fact that module federation requires configuration (there is no sensible default) and no existing configuration files (e.g. jsconfig.json / tsconfig.json) supports it yet, I can't see anyway module federation can land in CRA in near future.

I could see it being possible but in a limited way. Not every part of CRA uses a standard config file, e.g. the "proxy" and src/setupProxy.js are wholly a CRA thing.

Federated module consumption would probably require federated modules to conform to a CRA specified convention. So only a minimal amount of "configuration" is necessary, e.g. a simple declaration in package.json of what federated module libraries there are to import.

As for exposing federated modules. If module federation is heavy CRA might not offer it; but if it's light a new CRA version (probably 5+ not 4) might just always expose its build in a way that can be consumed according to CRA's conventions.

Also if the other issue(s) asking for a way to have multiple entrypoints are accepted I could also see CRA internally using module federation.

dantman avatar Oct 25 '20 07:10 dantman

I could see it being possible but in a limited way. Not every part of CRA uses a standard config file, e.g. the "proxy" and src/setupProxy.js are wholly a CRA thing.

Good point 👍

Also if the other issue(s) asking for a way to have multiple entrypoints are accepted I could also see CRA internally using module federation.

Do you mean this issue? That's a long thread, but sorry I can't find any conclusion on that thread that states multiple entrypoints will be supported.


To clarify I will be happy if CRA supports module federation out-out-the-box, but based on my personal observations, CRA has been fairly reserved about new features except when those are officially recommended tools by React (e.g. Fast Refresh, JSX Transform etc.) Also since module federation is new and other more customizable tools (e.g. NextJS) are not supporting module federation yet, I'm not optimistic with CRA supporting this soon.

Anyway, I hope I am wrong 😆

malcolm-kee avatar Oct 25 '20 07:10 malcolm-kee

Atm. we are testing our own "CRA" compatible build (written in typescript using wp5) adding the ability to configure using an mfconfig.json or for advanced usage mfconfig.js - it's basically just providing the FederatedModuleOptions for now. Because other systems should also provide typings and an "offline" version / fallback we are considering if part of the configuration could be shipped as part of the provider package.

... but not sure if we could have a mfconfig-experimental.js config file in CRA to get started gathering feedback to figure out where this will take us?

raix avatar Nov 20 '20 21:11 raix

Any update on Module Federation support on CRA?

AvishekNath avatar Jan 06 '21 04:01 AvishekNath

Any update on Module Federation support on CRA?

Yes. Pls. I am waiting for the same as well.

kumarlachhani avatar Feb 09 '21 19:02 kumarlachhani

CRA is not webpack 5 yet - also the webpack-dev-server doesn't support module federation yet.

raix avatar Feb 09 '21 22:02 raix

Will eject-ing the app and owning the configuration help the cause? I understand CRA will always want to be 0 configuration app. Module federation will require customisations defeating the goal... 😕

kumarldh avatar Mar 12 '21 08:03 kumarldh

Will eject-ing the app and owning the configuration help the cause? I understand CRA will always want to be 0 configuration app. Module federation will require customisations defeating the goal... 😕

I have tried to fork the create-react-app for my custom-react-scripts version so that it can be updated from upstream i.e. CRA for future updates but then due to breaking changes of WebPack 5, ejecting is the only option we have right now..

kumarlachhani avatar Mar 17 '21 19:03 kumarlachhani

Does any news relate to the update of CRA to working with webpack 5 ?

Do you think that starting a CRA project with eject and module federation for now and updating in the future will be an easier thing?

OriAmir avatar May 26 '21 12:05 OriAmir

(I reverted experimental mf support in the wp5 update pr for now, had an issue with chunk splitting - but should be fairly easy to add - for now first step is to update)

raix avatar May 26 '21 13:05 raix

@raix can't understand you.. you say that as first step module federation will not be part of the update but it's will be in the future ?

When actually CRA will realise version that includes the support in webpack 5?

So if I want to use that now you advice me to eject or to wait to CRA with webpack 5? ( should the eject will do problems later because of CRA actually use webpack 4....and may be conflicts ?)

Thanks!!!!

OriAmir avatar May 26 '21 22:05 OriAmir

What I'm saying is that there is a reverted commit showing how little effort adding support would be/an example. It's reverted for two reasons 1. There was an issue with split chunks likely 2. I'm not sure if it would be accepted, so rather prioritize wp5.

raix avatar May 27 '21 04:05 raix

Anyone with a positive experience of ejecting CRA and implementing module federation?

coderbit-net avatar Jun 01 '21 07:06 coderbit-net

I didn't eject a CRA, however I started adding my own webpack configs and modified package.json to run my build scripts, it was in Feb. It worked for me for a POC

kumarldh avatar Jun 02 '21 04:06 kumarldh

in addition to @AlexCoderBit question: is it possible at all to eject and to config or we will have many conflicts between webpack 4 to 5? I think it's will take time until CRA will integrate the module federation inside, basically, if CRA will support the webpack 5 itself I think that we will have easier life..

OriAmir avatar Jun 02 '21 11:06 OriAmir