[Angular][Module Federation] Router issue after updating nx from 14.5.8 to 14.8.2
See original GitHub issueCurrent Behavior
I have simple POC (master branch): https://github.com/DamianTt/NxAngularModuleFederationDocker that works with nx 14.5.8. It has Module Federation architecture - host and remotes. Remotes have defined routing as RouterModule.forChild([…]). Unfortunately it doesn’t work after update nx version to 14.8.2 (see failure log below). There is no error if I remove routing from remote app - that’s why I think the problem is connected with Angular Router
Expected Behavior
Routing in remote app works after updating nx version to 14.8.2
Steps to Reproduce
https://github.com/DamianTt/NxAngularModuleFederationDocker/tree/routerIssue - branch routerIssue. Run npm run dev, navigate to http://localhost:4200/, then click ‘App1’ and you will see an error in console.
- Create Nx workspace
- Create Host application
- Create Remote application
- Add routing to remote application as RouterModule.forChild([…])
Failure Logs
Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with `EnvironmentInjector#runInContext`. Find more at https://angular.io/errors/NG0203
at injectInjectorOnly (core.mjs:4775:15)
at Module.ɵɵinject (core.mjs:4786:12)
at Object.RouterModule_Factory [as useFactory] (router.mjs:7026:1)
at Object.factory (core.mjs:6974:38)
at R3Injector.hydrate (core.mjs:6887:35)
at R3Injector.get (core.mjs:6775:33)
at injectInjectorOnly (core.mjs:4782:33)
at ɵɵinject (core.mjs:4786:12)
at useValue (core.mjs:6567:65)
at R3Injector.resolveInjectorInitializers (core.mjs:6824:17)
at resolvePromise (zone.js:1211:31)
at resolvePromise (zone.js:1165:17)
at zone.js:1278:17
at _ZoneDelegate.invokeTask (zone.js:406:31)
at Object.onInvokeTask (core.mjs:26218:33)
at _ZoneDelegate.invokeTask (zone.js:405:60)
at Zone.runTask (zone.js:178:47)
at drainMicroTaskQueue (zone.js:585:35)
Environment
OS : win32 x64
npm : 8.1.2
nx : 14.8.2
@nrwl/angular : 14.8.2
@nrwl/cypress : 14.8.2
@nrwl/detox : Not Found
@nrwl/devkit : 14.8.2
@nrwl/esbuild : Not Found
@nrwl/eslint-plugin-nx : 14.8.2
@nrwl/expo : Not Found
@nrwl/express : Not Found
@nrwl/jest : 14.8.2
@nrwl/js : 14.8.2
@nrwl/linter : 14.8.2
@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 : 14.8.2
@nrwl/web : Not Found
@nrwl/webpack : 14.8.2
@nrwl/workspace : 14.8.2
typescript : 4.8.4
---------------------------------------
Local workspace plugins:
---------------------------------------
Community plugins:
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Error after updating to 15.1.1 · Issue #13211 · nrwl/nx - GitHub
Current Behavior I got a error with module-federation after updating from 15.0.4 to 15.1.1 Error: import('@nrwl/react/module-federation').
Read more >inject() must be called from an injection context (a constructor ...
Angular module federation with multiple angular versions of angular core for ... Federation] Router issue after updating nx from 14.5.8 to 14.8.2#12369.
Read more >Pitfalls with Module Federation and Angular
In this article, I'm going to destroy my Module Federation example! However, you don't need to worry: It's for a very good reason....
Read more >@angular-architects/module-federation - npm
The module federation config is a partial webpack configuration. It only contains stuff to control module federation. The rest is generated by ...
Read more >Angular Module Federation: How to configure isolated routing ...
The solution depends on how tightly you want to couple your remotes and your shell and where do you want to put the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hey 😃 This issue has been resolved in a recent fix and it’ll be released on a stable release with Nx 15.
For now, if you’d like to avail of the fix you can run
nx migrate nextandnx migrate --run-migrations.I hope this helps!
We will be working to make
@nrwl/angularcompatible with more versions of Anguar in the near future. At that stage you should be able to migrate the tooling independently to your angular version