#Ngx Module Federation-Angular

27 messages · Page 1 of 1 (latest)

late tundra
#

if the remote application is down, the host application crashes as well. This behavior is causing unexpected disruptions.

Could any one please suggest a way to handle this scenario gracefully, perhaps by adding error handling or a fallback mechanism?

My main.ts file
import {loadManifest } from '@angular-architects/module-federation';

loadManifest('assets/mf.manifest.json')
.catch(err => console.error(err))
.then(_ => import('./bootstrap'))
.catch(err => console.error(err));

and my app-routing.module.ts
{
path: 'remote',
loadChildren: () => loadRemoteModule({
type: 'manifest',
remoteName: 'remote',
exposedModule: './cadmin'
}).then(r => r.cadmin)
},
I have added logs in every host module, the logs are printing, basically , I am verifying if the remote app is down, whether the host app is initializing properly or not, the host bootstrapping properly , How to run host app smoothly, even remote app down?

I am getting below error

Uncaught (in promise): TypeError: angular_core__WEBPACK_IMPORTED_MODULE_0_.ɵɵtemplate(...) is not a function TypeError: angular_core__WEBPACK_IMPORTED_MODULE_0_.ɵɵtemplate(...) is not a function at MatFormField_Template (http://localhost:4200/node_modules_angular_material_fesm2022_form-field_mjs-_29e30.js:4580:115) at executeTemplate

Note: when the Remote App is not down, its working fine, i am getting above issue only when the remote app is down

compact seal
#

Did you try to append a .catch() to that .then(...)?
I suppose in case of errore that promise should reject.

late tundra
#

tried every thing , i haved added catch , in that catchblock i haved log, its not working

compact seal
#

I mean the promise returned by loadRemoteModule.
What have you tried?

late tundra
#

{
path: 'remote',
loadChildren: () => loadRemoteModule({
type: 'manifest',
remoteName: 'remote', // The name that is written in assets/mf.manifest.json
exposedModule: './cadmin'
}).catch(() => console.error('Error loading remote module' , '====================')).then(r => r.remote_routes),canActivate:[AuthGuard]
},
i have tried this , log is not printiing

compact seal
#

put then before catch

late tundra
#

already i have done , same issue

compact seal
#

are you getting the error routing to the remote or on booting of the host?

late tundra
#

from the host

compact seal
#

is there an automatic routing to that remote in host bootstrapping?

late tundra
#

no, i have added only in app-routing.module.ts

#

{
path: 'remote',
loadChildren: () => loadRemoteModule({
type: 'manifest',
remoteName: 'remote', // The name that is written in assets/mf.manifest.json
exposedModule: './cadmin'
}).catch(() => console.error('Error loading remote module' , '====================')).then(r => r.remote_routes),canActivate:[AuthGuard]
}, except this nothing

compact seal
#

are you sure the error comes from that remote?

late tundra
#

error comes from host

#

100% percent error from host, becaue when i give correct URL of remote app, its working , wantedly i have given wrong URL of remote app to test, if remote app down, host should run smoothly

compact seal
#

please, explain how are you testing the wrong address.

late tundra
compact seal
#

and none of those catch under loadManifest print the error?

late tundra
#

in main.ts its logging the error

#

this is my main.ts file
import {loadManifest } from '@angular-architects/module-federation';

loadManifest('assets/mf.manifest.json')
.catch(err => console.error(err))
.then(_ => import('./bootstrap'))
.catch(err => console.error(err));
in the at first catch its logging the error

compact seal
#

if commentout the entry in your manifest, instead of passing a wrong one, the host app boots correctly?

late tundra
#

Yes, if we give correct one

compact seal
#

I asked if you comment out that entry. Or if you delete it.

late tundra
#

We need to give something in it, because we are loading that manifest.json in main.ts file

compact seal
#

I don't know what to say.
The error you posted in the first message has nothing to do with module federation.
Looks like a problem with material library, maybe a version mismatch or a missing import.

late tundra
#

If it is version mismatch, when i give correct URL, it should not work right