Closed delairec closed 2 years ago
I have to add that without module-federation (without custom webpack config) and using loadRemoteModule method, the server side rendering is working (but without remote apps as one can expect).
Has anyone had time to look into this ? Should I open an issue on webpack side ? Is there any known workaround ?
We are currently in a POC phase at my company and SSR is a must have for us. I really want to use Nx though. Any help will be strongly appreciated.
Related issue: https://github.com/nrwl/nx/issues/10887
We're aware SSR does not work with Module Federation and we're working with @ScriptedAlchemy to push Module Federation support to SSR via Node.
This is on our roadmap and we're actively working on it.
As this is a duplicate issue, I'm going to close this one to ensure that we keep all discussions in one place.
Yep, I'm ready to publish module-Federation/node to npm.
Just waiting for the team to confirm it works for their use case.
Readme also needs serious love - but the tech should work. I lifted it out of my nextjs plugin which has been pretty stable for months in node Federation.
Good to hear, thank you !
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
I cannot start my SSR server in dev environment and I don't know how to solve errors that come up.
Expected Behavior
I want to be able to add SSR to my project and start dev server without error.
Steps to Reproduce
I can't push on public repos because of my company vpn, so I will detail the steps.
I tried to follow this tuto https://blog.nrwl.io/server-side-rendering-ssr-with-angular-for-nx-workspaces-14e2414ca532 But I need to adapt some things because I use module federation.
First, I generate a workspace with a host and a remote app. For this, I use these commands in a shell :
npx create-nx-workspace nx-14-module-federation-with-ssr
npm i @nrwl/angular
nx g @nrwl/angular:host example-shell
nx g @nrwl/angular:remote example-remote --host=example-shell --port=4201
npm i @nguniversal/express-engine --legacy-peer-deps
npm i @nguniversal/builders --save-dev
Here, I need to move bootstrap.ts code into main.ts code to avoid a
Bootstrap module not found
error in the next step.nx generate @schematics/angular:universal --project=example-shell
Then I move back the altered code in main.ts to bootstrap.ts file (in order to make the app work again).
Next, I update config files :
outputPath
in project.jsonangularCompilerOptions.entryModule
prop)This is were the tutorial ends. But to handle module federation, I need a custom webpack configuration (if not, I have
module not found
error because it can't resolveexample-remote/Module
.npm i --save-dev @angular-builders/custom-webpack
@angular-builders/custom-webpack:server
as executor and addcustomWebpackConfig.path
inoptions
nx run example-shell:serve-ssr
This is were I'm stuck. I tried many things but in the end, even if I got the builds complete, then when I try to
nx run example-shell:serve-ssr
I have server errors mainly because of imports in the generated main.js file (it tries to import the remote).Mainly, I played with these webpack options :
target
output.chunkFormat
output.libraryTarget
externals
externalsType
For this, I had to update webpack.config.js like this :
Failure Logs
With basic webpack.config.js, the build ends in error :
When builds complete and server try to start :
When I try to add the type module in package.json :
Environment