nx: Module Federation SSR error: "Shared module is not available for eager consumption"
Current Behavior
Following https://blog.nrwl.io/setting-up-module-federation-with-server-side-rendering-for-angular-66bae10ead2d from @colum
In a host/remotes scenario (dashboard/login),
When serving the host with SSR
npx nx serve-ssr dashboard
got the error:
if(typeof factory !== "function") throw new Error("Shared module is not available for eager consumption: " + id);
thown at dist/apps/login/server/main.js
Also got the same when running: npx nx serve-ssr login and when running npx nx serve login
But, works well when running npx nx serve dashboard
Expected Behavior
Be able to run a host/remotes module federation with SSR
Github Repo
No response
Steps to Reproduce
- npx create-nx-workspace@latest myorg
- npm install @nrwl/angular
- npx nx g host dashboard --remotes=login --ssr
- npx nx serve-ssr dashboard
Nx Report
Node : 18.12.1
OS : win32 x64
npm : 8.6.0
nx : 15.5.1
@nrwl/angular : 15.5.1
@nrwl/cypress : 15.5.1
@nrwl/detox : Not Found
@nrwl/devkit : 15.5.1
@nrwl/esbuild : Not Found
@nrwl/eslint-plugin-nx : 15.5.1
@nrwl/expo : Not Found
@nrwl/express : Not Found
@nrwl/jest : 15.5.1
@nrwl/js : 15.5.1
@nrwl/linter : 15.5.1
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/nx-cloud : Not Found
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/rollup : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : Not Found
@nrwl/web : Not Found
@nrwl/webpack : 15.5.1
@nrwl/workspace : 15.5.1
@nrwl/vite : Not Found
typescript : 4.8.4
---------------------------------------
Local workspace plugins:
---------------------------------------
Community plugins:
@nguniversal/express-engine: 15.0.0
@nguniversal/builders: 15.0.0
Failure Logs
No response
Additional Information
Module federation works as expected with non-SSR apps. This problem only arises with SSR. So, it is more related to SSR than to Module Federation. Thanks
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 3
- Comments: 26 (6 by maintainers)
@AlbertoBasalo, @cooleso i solved problem using modified solution by @ktordoff13
Works for me on Windows
Hi, thank you @ktordoff13, were you on windows or another OS ?
I tried to add the additionalShared array and it had no effect on my project on windows. However on linux I could launch the login (remote) app, but it had no SSR : is it the expected behavior in dev mode ?
When I’ll have more time I will give it a try in production mode as well, and I need to check what could be the impacts of such a configuration in the final build.
I just pushed it now
Hi @delairec
There is an issue to track this on the Module Federation side here: https://github.com/module-federation/universe/issues/604