ERROR Error: Uncaught (in promise): Error: RouterModule.forRoot() called twice. Lazy loaded modules should use RouterModule.forChild() instead.
问题:我使用的是"webpack":"5.67.0“和”@角-架构师/模块-联邦“:"^14.1.1",我的主机应用程序和远程应用程序都是独立工作的。但是当我尝试查看shell内部的远程应用程序时,它给了我从上面的错误。当我将forChild()添加到远程时,我的样式和图像并不来自远程,它们只来自主机。我做错了什么?
来自主机的Webpack配置:
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: "container",
publicPath: "auto"
},
optimization: {
runtimeChunk: false
},
resolve: {
alias: {
...sharedMappings.getAliases(),
}
},
experiments: {
outputModule: true
},
plugins: [
new ModuleFederationPlugin({
library: { type: "module" },
// For remotes (please adjust)
// name: "container",
// filename: "remoteEntry.js",
// exposes: {
// './Component': './/src/app/app.component.ts',
// },
// For hosts (please adjust)
remotes: {
"web": "http://localhost:8081/remoteEntry.js",
},
shared: share({
"@angular/core": { singleton: true, strictVersion: true, eager: true, requiredVersion: '>= 13.2.4' },
"@angular/common": { singleton: true, strictVersion: true, eager: true, requiredVersion: '>= 13.2.4' },
"@angular/common/http": { singleton: true, strictVersion: true, eager: true, requiredVersion: '>= 13.2.4' },
"@angular/router": { singleton: true, strictVersion: true, eager: true, requiredVersion: '>= 13.2.4' },
...sharedMappings.getDescriptors()
})
}),
sharedMappings.getPlugin()
],
};Webpack配置来自远程:
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'),
['home']);
module.exports = {
output: {
uniqueName: "web",
publicPath: "auto"
},
optimization: {
runtimeChunk: false
},
resolve: {
alias: {
...sharedMappings.getAliases(),
}
},
experiments: {
outputModule: true
},
module: {
rules: [
{
test: /\.svg$/,
use: [
{
loader: 'svg-url-loader',
options: {
limit: 10000,
},
},
],
},
{
test: /\.jpe?g$|\.ico$|\.gif$|\.png$|\.svg$|\.woff$|\.ttf$|\.wav$|\.mp3$|\.css/,
use: {
loader: 'file-loader?name=[name].[ext]'
}
}
]
},
plugins: [
new ModuleFederationPlugin({
library: { type: "module" },
name: "web",
filename: "remoteEntry.js",
exposes: {
'./WebsiteModule': './src/app/app.module.ts',
},
shared:
share({
"@angular/core": { singleton: true, strictVersion: true, eager: true, requiredVersion: '>= 13.2.4', },
"@angular/common": { singleton: true, strictVersion: true, eager: true, requiredVersion: '>= 13.2.4', },
"@angular/common/http": { singleton: true, strictVersion: true, eager: true, requiredVersion: '>= 13.2.4', },
"@angular/router": { singleton: true, strictVersion: true, eager: true, requiredVersion: '>= 13.2.4', },
"@angular/material": { singleton: true, strictVersion: true, eager: true },
"@angular/cdk": { singleton: true, strictVersion: true, eager: true },
...sharedMappings.getDescriptors()
})
}),
sharedMappings.getPlugin()
],
};发布于 2022-06-07 01:45:42
我相信您可以更改为微前端服务的url的汽车公共路径,例如
publicPath: "auto"至
publicPath: "localhost:5000"https://stackoverflow.com/questions/71326434
复制相似问题