Cannot load a MFE Angular app created with NX on host angular integrated with module-federation

I have created a application with :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>npx create-nx-workspace@latest angular -monorepo --preset=angular-monorepo
</code>
<code>npx create-nx-workspace@latest angular -monorepo --preset=angular-monorepo </code>
npx create-nx-workspace@latest angular -monorepo --preset=angular-monorepo

and added host and a remote application with nx extention available on vs-code.

here the both are working as expected running the host will automatically run the remote(in localhost:4204) also in the nx workspace, accessing the host on localhost:4203 and routing to localhost:4203/remote1 will display the remote content in the host.
host configurations: app.routes.ts

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { authGuard } from './auth.guard';
import { NxWelcomeComponent } from './nx-welcome.component';
import { Route } from '@angular/router';
export const appRoutes: Route[] = [
{
path: 'remote1',
loadChildren: () => import('remote1/Routes').then((m) => m.remoteRoutes),
canActivate: [authGuard],
},
{
path: '',
component: NxWelcomeComponent,
},
];
</code>
<code>import { authGuard } from './auth.guard'; import { NxWelcomeComponent } from './nx-welcome.component'; import { Route } from '@angular/router'; export const appRoutes: Route[] = [ { path: 'remote1', loadChildren: () => import('remote1/Routes').then((m) => m.remoteRoutes), canActivate: [authGuard], }, { path: '', component: NxWelcomeComponent, }, ]; </code>
import { authGuard } from './auth.guard';
import { NxWelcomeComponent } from './nx-welcome.component';
import { Route } from '@angular/router';

export const appRoutes: Route[] = [
  {
    path: 'remote1',
    loadChildren: () => import('remote1/Routes').then((m) => m.remoteRoutes),
    canActivate: [authGuard],
  },
  {
    path: '',
    component: NxWelcomeComponent,
  },
];

module-federation.config.ts

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { ModuleFederationConfig } from '@nx/webpack';
const config: ModuleFederationConfig = {
name: 'host',
remotes: ['remote1'],
};
export default config;
</code>
<code>import { ModuleFederationConfig } from '@nx/webpack'; const config: ModuleFederationConfig = { name: 'host', remotes: ['remote1'], }; export default config; </code>
import { ModuleFederationConfig } from '@nx/webpack';

const config: ModuleFederationConfig = {
  name: 'host',
  remotes: ['remote1'],
};
export default config;

host app app.component.html

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><ul class="remote-menu">
<li><a routerLink="/">Home</a></li>
<li><a routerLink="remote1">Remote1</a></li>
</ul>
<router-outlet></router-outlet>
</code>
<code><ul class="remote-menu"> <li><a routerLink="/">Home</a></li> <li><a routerLink="remote1">Remote1</a></li> </ul> <router-outlet></router-outlet> </code>
<ul class="remote-menu">
  <li><a routerLink="/">Home</a></li>
  <li><a routerLink="remote1">Remote1</a></li>
</ul>
<router-outlet></router-outlet>

/////////////////////////////////
remote1 configurations: app.routes.ts

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { Route } from '@angular/router';
export const appRoutes: Route[] = [
{
path: '',
loadChildren: () =>
import('./remote-entry/entry.routes').then((m) => m.remoteRoutes),
},
];
</code>
<code>import { Route } from '@angular/router'; export const appRoutes: Route[] = [ { path: '', loadChildren: () => import('./remote-entry/entry.routes').then((m) => m.remoteRoutes), }, ]; </code>
import { Route } from '@angular/router';

export const appRoutes: Route[] = [
  {
    path: '',
    loadChildren: () =>
      import('./remote-entry/entry.routes').then((m) => m.remoteRoutes),
  },
];

module-federation.config.ts

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { ModuleFederationConfig } from '@nx/webpack';
const config: ModuleFederationConfig = {
name: 'remote1',
exposes: {
'./Routes': 'apps/remote1/src/app/remote-entry/entry.routes.ts',
'./RemoteComponent' : 'apps/remote1/src/app/remote-entry/entry.component.ts'
},
};
export default config;
</code>
<code>import { ModuleFederationConfig } from '@nx/webpack'; const config: ModuleFederationConfig = { name: 'remote1', exposes: { './Routes': 'apps/remote1/src/app/remote-entry/entry.routes.ts', './RemoteComponent' : 'apps/remote1/src/app/remote-entry/entry.component.ts' }, }; export default config; </code>
import { ModuleFederationConfig } from '@nx/webpack';

const config: ModuleFederationConfig = {
  name: 'remote1',
  exposes: {
    './Routes': 'apps/remote1/src/app/remote-entry/entry.routes.ts',
    './RemoteComponent' : 'apps/remote1/src/app/remote-entry/entry.component.ts'
  },
};

export default config;

These are my nx workspace remote and host app , I need to access this remote1 in my angular application created with ng new host, added module federation with

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>ng add @angular-architects/module-federation --project host --port 4200
</code>
<code>ng add @angular-architects/module-federation --project host --port 4200 </code>
ng add @angular-architects/module-federation --project host --port 4200

webpack.config.js

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const mf = require("@angular-architects/module-federation/webpack");
const path = require("path");
const share = mf.share;
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(
path.join(__dirname, 'tsconfig.json'),
[/* mapped paths to share */]);
module.exports = {
output: {
uniqueName: "hostApp",
publicPath: "auto",
scriptType: "text/javascript"
},
optimization: {
runtimeChunk: false
},
resolve: {
alias: {
...sharedMappings.getAliases(),
}
},
experiments: {
outputModule: true
},
plugins: [
new ModuleFederationPlugin({
// library: { type: "Routes" },
// For remotes (please adjust)
// name: "hostApp",
// filename: "remoteEntry.js",
// exposes: {
// './Component': './/src/app/app.component.ts',
// },
// For hosts (please adjust)
remotes: {
"remote1": "remote1@http://localhost:4204/remoteEntry.mjs",
},
// shared: share({
// "@angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
// "@angular/common": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
// "@angular/common/http": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
// "@angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
// ...sharedMappings.getDescriptors()
// })
}),
sharedMappings.getPlugin()
],
};
</code>
<code>const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin"); const mf = require("@angular-architects/module-federation/webpack"); const path = require("path"); const share = mf.share; const sharedMappings = new mf.SharedMappings(); sharedMappings.register( path.join(__dirname, 'tsconfig.json'), [/* mapped paths to share */]); module.exports = { output: { uniqueName: "hostApp", publicPath: "auto", scriptType: "text/javascript" }, optimization: { runtimeChunk: false }, resolve: { alias: { ...sharedMappings.getAliases(), } }, experiments: { outputModule: true }, plugins: [ new ModuleFederationPlugin({ // library: { type: "Routes" }, // For remotes (please adjust) // name: "hostApp", // filename: "remoteEntry.js", // exposes: { // './Component': './/src/app/app.component.ts', // }, // For hosts (please adjust) remotes: { "remote1": "remote1@http://localhost:4204/remoteEntry.mjs", }, // shared: share({ // "@angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto' }, // "@angular/common": { singleton: true, strictVersion: true, requiredVersion: 'auto' }, // "@angular/common/http": { singleton: true, strictVersion: true, requiredVersion: 'auto' }, // "@angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto' }, // ...sharedMappings.getDescriptors() // }) }), sharedMappings.getPlugin() ], }; </code>
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const mf = require("@angular-architects/module-federation/webpack");
const path = require("path");
const share = mf.share;

const sharedMappings = new mf.SharedMappings();
sharedMappings.register(
  path.join(__dirname, 'tsconfig.json'),
  [/* mapped paths to share */]);

module.exports = {
  output: {
    uniqueName: "hostApp",
    publicPath: "auto",
    scriptType: "text/javascript"
  },
  optimization: {
    runtimeChunk: false
  },
  resolve: {
    alias: {
      ...sharedMappings.getAliases(),
    }
  },
  experiments: {
    outputModule: true
  },
  plugins: [
    new ModuleFederationPlugin({
        // library: { type: "Routes" },

        // For remotes (please adjust)
        // name: "hostApp",
        // filename: "remoteEntry.js",
        // exposes: {
        //     './Component': './/src/app/app.component.ts',
        // },

        // For hosts (please adjust)
        remotes: {
            "remote1": "remote1@http://localhost:4204/remoteEntry.mjs",
        },

        // shared: share({
        //   "@angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
        //   "@angular/common": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
        //   "@angular/common/http": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
        //   "@angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto' },

        //   ...sharedMappings.getDescriptors()
        // })

    }),
    sharedMappings.getPlugin()
  ],
};

app.routes.ts

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { loadRemoteModule } from '@angular-architects/module-federation';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
export const routes: Routes = [
{ path: "",component: AppComponent},
{path: "remote1", loadChildren: () =>{
return loadRemoteModule({
remoteEntry : "http://localhost:4204/remoteEntry.mjs",
remoteName : "remote1",
exposedModule: "remote1/RemoteComponent"
}).then(m => m.RemoteComponentModule).catch(err => console.log(err))
}
},
];
</code>
<code>import { loadRemoteModule } from '@angular-architects/module-federation'; import { Routes, RouterModule } from '@angular/router'; import { AppComponent } from './app.component'; export const routes: Routes = [ { path: "",component: AppComponent}, {path: "remote1", loadChildren: () =>{ return loadRemoteModule({ remoteEntry : "http://localhost:4204/remoteEntry.mjs", remoteName : "remote1", exposedModule: "remote1/RemoteComponent" }).then(m => m.RemoteComponentModule).catch(err => console.log(err)) } }, ]; </code>
import { loadRemoteModule } from '@angular-architects/module-federation';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';

export const routes: Routes = [
{ path: "",component: AppComponent},

{path: "remote1", loadChildren: () =>{
    return loadRemoteModule({
    remoteEntry : "http://localhost:4204/remoteEntry.mjs",
    remoteName : "remote1",
    exposedModule: "remote1/RemoteComponent"
    }).then(m => m.RemoteComponentModule).catch(err => console.log(err))
}  
},

];

app.component.html

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><ul class="remote-menu">
<li><a routerLink="/">Home</a></li>
<li><a routerLink="/remote1">Remote1</a></li>
</ul>
Home Works
<router-outlet></router-outlet>
</code>
<code><ul class="remote-menu"> <li><a routerLink="/">Home</a></li> <li><a routerLink="/remote1">Remote1</a></li> </ul> Home Works <router-outlet></router-outlet> </code>
<ul class="remote-menu">
  <li><a routerLink="/">Home</a></li>
  <li><a routerLink="/remote1">Remote1</a></li>
</ul>
Home Works
<router-outlet></router-outlet>

When tried running only the remote1 with nx serve remote1 on localhost:4204 and running the angular application with ng serve on localhost:4200
Im getting these 2 errors and remote1 is not getting printed.

Error Typerror: container is undefined

For the first one I tried to add the

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>scriptType: 'text/javascript'
</code>
<code>scriptType: 'text/javascript' </code>
scriptType: 'text/javascript' 

but that section is not available on the remote app created with nx.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật