我正在尝试用实现模块联邦,但我面临一个问题,不知道如何修复它。
的问题是:当X应用程序懒惰从使用Firebase的Y应用程序加载模块时,module不识别fire auth提供程序。
我有两个应用程序:、Auth、和仪表板。
我的Auth应用程序使用firebase进行用户登录。
防火墙请求登录是通过NgRX效果进行的:
import {AngularFireAuth} from '@angular/fire/auth';
@Injectable()
export class AuthEffects {
userLogin$: Observable<Action> = createEffect(() => {
/* effect implementation */
});
constructor(private fireAuth: AngularFireAuth){}
}AuthModule导入:
imports: [
/* ...other imports */
StoreModule.forFeature('authState', authReducer),
EffectsModule.forFeature([AuthEffects]),
AngularFireModule.initializeApp(firebaseConfig),
AngularFireAuthModule
]仪表板AppRoutingModule导入:
const routes: Routes = [
{
path: '',
pathMatch: 'full',
loadChildren: () => import('auth/AuthModule').then(m => m.AuthModule)
}
];
@NgModule({
imports: [
RouterModule.forRoot(routes)
],
exports: [RouterModule]
})当我只启动Auth应用程序时,一切正常,我可以登录。
但是,当我试图远程使用Auth应用程序时,在仪表板应用程序中,我会得到以下错误:
NullInjectorError: StaticInjectorError(AppModule)[InjectionToken angularfire2.app.options]:
StaticInjectorError(Platform: core)[InjectionToken angularfire2.app.options]:
NullInjectorError: No provider for InjectionToken angularfire2.app.options!部分Auth - webpack.config.js
plugins: [
new ModuleFederationPlugin({
name: 'auth',
library: {type: 'var', name: 'auth'},
filename: 'remoteEntry.js',
exposes: {
'./AuthModule': './src/app/login/auth.module.ts',
'./AuthComponent': './src/app/login/auth.component.ts',
'./AuthActions': './src/app/store/actions/auth.actions.ts',
'./AuthReducer': './src/app/store/reducers/auth.reducer.ts',
'./AuthEffects': './src/app/store/effects/auth.effects'
},
shared: {
...dependencies,
'@angular/core': {
requiredVersion: dependencies['@angular/core'],
singleton: true,
},
'@angular/common': {
requiredVersion: dependencies['@angular/common'],
singleton: true,
},
'@angular/router': {
requiredVersion: dependencies['@angular/router'],
singleton: true,
}
}
})
]疟疾仪表板- webpack.config.js
plugins: [
new ModuleFederationPlugin({
name: 'dashboard',
library: {type: 'var', name: 'dashboard'},
filename: 'remoteEntry.js',
remotes: {
auth: 'auth',
},
shared: {
...dependencies,
'@angular/core': {
requiredVersion: dependencies['@angular/core'],
singleton: true,
},
'@angular/common': {
requiredVersion: dependencies['@angular/common'],
singleton: true,
},
'@angular/router': {
requiredVersion: dependencies['@angular/router'],
singleton: true,
}
}
})
]我试图自己解决它,但模块联盟是一个新的东西,我们有很少的帖子。
有人能帮我吗?如果你来这之前,非常感谢你!
发布于 2020-08-12 06:57:45
解决了!
谢谢扎克·杰克逊我能解决这个问题。
解决方案:
https://github.com/module-federation/module-federation.github.io/issues/14#issuecomment-672647713
https://stackoverflow.com/questions/63368656
复制相似问题