admin管理员组文章数量:1313752
I am trying to achieve a very simple module federation with shell (host) and travel (remote). Whenever I try do dynamically load the AbcModule from travel I get the following error in the shell:
ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'init') TypeError: Cannot read properties of undefined (reading 'init') at angular-architects-module-federation-runtime.js:26:1 at Generator.next () at fulfilled (tslib.es6.js:73:43) at _ZoneDelegate.invoke (zone.js:372:1) at Object.onInvoke (core.mjs:25634:33) at _ZoneDelegate.invoke (zone.js:371:1) at Zone.run (zone.js:134:1) at zone.js:1275:1 at _ZoneDelegate.invokeTask (zone.js:406:1) at Object.onInvokeTask (core.mjs:25621:33) at resolvePromise (zone.js:1211:1) at zone.js:1118:1 at fulfilled (tslib.es6.js:73:86) at _ZoneDelegate.invoke (zone.js:372:1) at Object.onInvoke (core.mjs:25634:33) at _ZoneDelegate.invoke (zone.js:371:1) at Zone.run (zone.js:134:1) at zone.js:1275:1 at _ZoneDelegate.invokeTask (zone.js:406:1) at Object.onInvokeTask (core.mjs:25621:33)
ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'get') TypeError: Cannot read properties of undefined (reading 'get') at angular-architects-module-federation-runtime.js:9:1 at Generator.next () at tslib.es6.js:76:1 at new ZoneAwarePromise (zone.js:1427:1) at __awaiter (tslib.es6.js:72:1) at lookupExposedModule (angular-architects-module-federation-runtime.js:7:21) at angular-architects-module-federation-runtime.js:106:1 at Generator.next () at fulfilled (tslib.es6.js:73:43) at _ZoneDelegate.invoke (zone.js:372:1) at resolvePromise (zone.js:1211:1) at resolvePromise (zone.js:1165:1) at zone.js:1278:1 at _ZoneDelegate.invokeTask (zone.js:406:1) at Object.onInvokeTask (core.mjs:25621:33) at _ZoneDelegate.invokeTask (zone.js:405:1) at Zone.runTask (zone.js:178:1) at drainMicroTaskQueue (zone.js:585:1) at ZoneTask.invokeTask [as invoke] (zone.js:49
app routes from shell:
import { loadRemoteModule } from "@angular-architects/module-federation";
import { Routes } from "@angular/router";
import { TestComponent } from "./test/testponent";
export const APP_ROUTES: Routes = [
{
path: '',
ponent: TestComponent,
pathMatch: 'full'
},
{
path: 'abc',
loadChildren: () => loadRemoteModule({
remoteEntry: 'http://localhost:4201/remoteEntry.js',
remoteName: 'travel',
exposedModule: './Module'
})
.then(m => m.AbcModule)
}
];
webpack.config.js from shell:
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.base.json'),
[/* mapped paths to share */]);
module.exports = {
output: {
uniqueName: "shell",
publicPath: "auto"
},
optimization: {
runtimeChunk: false
},
resolve: {
alias: {
...sharedMappings.getAliases(),
}
},
experiments: {
outputModule: true
},
plugins: [
new ModuleFederationPlugin({
library: { type: "module" },
shared: share({
"@angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/mon": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/mon/http": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
...sharedMappings.getDescriptors()
})
}),
sharedMappings.getPlugin()
],
};
webpack.config.js from travel:
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.base.json'),
[/* mapped paths to share */]);
module.exports = {
output: {
uniqueName: "travel",
publicPath: "auto"
},
optimization: {
runtimeChunk: false
},
resolve: {
alias: {
...sharedMappings.getAliases(),
}
},
experiments: {
outputModule: true
},
plugins: [
new ModuleFederationPlugin({
library: { type: "module" },
name: "travel",
filename: "remoteEntry.js",
exposes: {
'./Module': './apps/travel/src/app/abc/abc.module.ts',
},
shared: share({
"@angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/mon": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/mon/http": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
...sharedMappings.getDescriptors()
})
}),
sharedMappings.getPlugin()
],
};
AbcModule from travel:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/mon';
import { AbcComponent } from './abc/abcponent';
import { RouterModule } from '@angular/router';
@NgModule({
declarations: [AbcComponent],
imports: [CommonModule, RouterModule.forChild([
{
path: '',
ponent: AbcComponent
}
])],
exports: [RouterModule]
})
export class AbcModule {}
I am trying to achieve a very simple module federation with shell (host) and travel (remote). Whenever I try do dynamically load the AbcModule from travel I get the following error in the shell:
ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'init') TypeError: Cannot read properties of undefined (reading 'init') at angular-architects-module-federation-runtime.js:26:1 at Generator.next () at fulfilled (tslib.es6.js:73:43) at _ZoneDelegate.invoke (zone.js:372:1) at Object.onInvoke (core.mjs:25634:33) at _ZoneDelegate.invoke (zone.js:371:1) at Zone.run (zone.js:134:1) at zone.js:1275:1 at _ZoneDelegate.invokeTask (zone.js:406:1) at Object.onInvokeTask (core.mjs:25621:33) at resolvePromise (zone.js:1211:1) at zone.js:1118:1 at fulfilled (tslib.es6.js:73:86) at _ZoneDelegate.invoke (zone.js:372:1) at Object.onInvoke (core.mjs:25634:33) at _ZoneDelegate.invoke (zone.js:371:1) at Zone.run (zone.js:134:1) at zone.js:1275:1 at _ZoneDelegate.invokeTask (zone.js:406:1) at Object.onInvokeTask (core.mjs:25621:33)
ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'get') TypeError: Cannot read properties of undefined (reading 'get') at angular-architects-module-federation-runtime.js:9:1 at Generator.next () at tslib.es6.js:76:1 at new ZoneAwarePromise (zone.js:1427:1) at __awaiter (tslib.es6.js:72:1) at lookupExposedModule (angular-architects-module-federation-runtime.js:7:21) at angular-architects-module-federation-runtime.js:106:1 at Generator.next () at fulfilled (tslib.es6.js:73:43) at _ZoneDelegate.invoke (zone.js:372:1) at resolvePromise (zone.js:1211:1) at resolvePromise (zone.js:1165:1) at zone.js:1278:1 at _ZoneDelegate.invokeTask (zone.js:406:1) at Object.onInvokeTask (core.mjs:25621:33) at _ZoneDelegate.invokeTask (zone.js:405:1) at Zone.runTask (zone.js:178:1) at drainMicroTaskQueue (zone.js:585:1) at ZoneTask.invokeTask [as invoke] (zone.js:49
app routes from shell:
import { loadRemoteModule } from "@angular-architects/module-federation";
import { Routes } from "@angular/router";
import { TestComponent } from "./test/test.ponent";
export const APP_ROUTES: Routes = [
{
path: '',
ponent: TestComponent,
pathMatch: 'full'
},
{
path: 'abc',
loadChildren: () => loadRemoteModule({
remoteEntry: 'http://localhost:4201/remoteEntry.js',
remoteName: 'travel',
exposedModule: './Module'
})
.then(m => m.AbcModule)
}
];
webpack.config.js from shell:
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.base.json'),
[/* mapped paths to share */]);
module.exports = {
output: {
uniqueName: "shell",
publicPath: "auto"
},
optimization: {
runtimeChunk: false
},
resolve: {
alias: {
...sharedMappings.getAliases(),
}
},
experiments: {
outputModule: true
},
plugins: [
new ModuleFederationPlugin({
library: { type: "module" },
shared: share({
"@angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/mon": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/mon/http": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
...sharedMappings.getDescriptors()
})
}),
sharedMappings.getPlugin()
],
};
webpack.config.js from travel:
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.base.json'),
[/* mapped paths to share */]);
module.exports = {
output: {
uniqueName: "travel",
publicPath: "auto"
},
optimization: {
runtimeChunk: false
},
resolve: {
alias: {
...sharedMappings.getAliases(),
}
},
experiments: {
outputModule: true
},
plugins: [
new ModuleFederationPlugin({
library: { type: "module" },
name: "travel",
filename: "remoteEntry.js",
exposes: {
'./Module': './apps/travel/src/app/abc/abc.module.ts',
},
shared: share({
"@angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/mon": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/mon/http": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
...sharedMappings.getDescriptors()
})
}),
sharedMappings.getPlugin()
],
};
AbcModule from travel:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/mon';
import { AbcComponent } from './abc/abc.ponent';
import { RouterModule } from '@angular/router';
@NgModule({
declarations: [AbcComponent],
imports: [CommonModule, RouterModule.forChild([
{
path: '',
ponent: AbcComponent
}
])],
exports: [RouterModule]
})
export class AbcModule {}
Share
Improve this question
asked May 13, 2022 at 18:34
StefanStefan
1,3724 gold badges19 silver badges49 bronze badges
1 Answer
Reset to default 7I got it working by changing the loadRemoteModule parameter to this:
import { loadRemoteModule } from "@angular-architects/module-federation";
import { Routes } from "@angular/router";
import { TestComponent } from "./test/test.ponent";
export const APP_ROUTES: Routes = [
{
path: '',
ponent: TestComponent,
pathMatch: 'full'
},
{
path: 'abc',
loadChildren: () => loadRemoteModule({
remoteEntry: 'http://localhost:4201/remoteEntry.js',
type: 'module',
exposedModule: './Module'
})
.then(m => m.AbcModule)
}
];
本文标签: javascriptAngular federated module can not be loaded when route would be activatedStack Overflow
版权声明:本文标题:javascript - Angular federated module can not be loaded when route would be activated - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741925064a2405233.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论