将 SAP Spartacus 作为 feature module 进行 Lazy Load 延迟加载时遇到的注入错误分析
Posted JerryWang汪子熙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将 SAP Spartacus 作为 feature module 进行 Lazy Load 延迟加载时遇到的注入错误分析相关的知识,希望对你有一定的参考价值。
将 SAP Spartacus 作为 feature module 进行 Lazy Load 延迟加载时,遇到如下错误:
ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(CatalogModule)[UserAuthEventModule -> UserAuthEventBuilder -> UserAuthEventBuilder -> AuthService -> OAuthLibWrapperService -> OAuthService -> OAuthService -> OAuthService]:
NullInjectorError: No provider for OAuthService!
NullInjectorError: R3InjectorError(CatalogModule)[UserAuthEventModule -> UserAuthEventBuilder -> UserAuthEventBuilder -> AuthService -> OAuthLibWrapperService -> OAuthService -> OAuthService -> OAuthService]:
NullInjectorError: No provider for OAuthService!
at NullInjector.get (core.js:11120:1)
at R3Injector.get (core.js:11287:1)
at R3Injector.get (core.js:11287:1)
at R3Injector.get (core.js:11287:1)
at injectInjectorOnly (core.js:4770:1)
at Module.ɵɵinject (core.js:4774:1)
at Object.OAuthLibWrapperService_Factory [as factory] (spartacus-core.js:1514:1)
at R3Injector.hydrate (core.js:11457:1)
at R3Injector.get (core.js:11276:1)
at injectInjectorOnly (core.js:4770: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.js:28679:1)
at _ZoneDelegate.invokeTask (zone.js:405:1)
at Zone.runTask (zone.js:178:1)
at drainMicroTaskQueue (zone.js:585:1)UserAuthEventModule
具体分析:
UserAuthEventModule 使用了 UserAuthEventBuilder 作为依赖:
UserAuthEventBuilder 使用了 AuthService:
AuthService 使用了 OAuthLibWrapperService
OAuthLibWrapperService 使用了 OAuthService
这个 OAuthService 最后来自 angular-oauth2-oidc
,一个开源的 Angular oAuth2 实现库:
OAuthService angular-oauth2-oidc
根据错误消息 No provider for OAuthService
在网上查找,发现下列这个 known issue:
https://github.com/manfredsteyer/angular-oauth2-oidc/issues/258
添加第 49 行的 OAuthModule.forRoot()
后,错误消失:
https://github.com/manfredsteyer/angular-oauth2-oidc/issues/241
UserAuthEventModule 被 UserAuthModule 所 import:
UserAuthModule 最后通过 index.ts 导出:
遇到新的错误:
ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(CatalogModule)[EffectsFeatureModule -> InjectionToken @ngrx/effects Feature Effects -> [object Object] -> LanguagesEffects -> SiteConnector -> SiteConnector -> SiteAdapter -> SiteAdapter -> SiteAdapter]:
NullInjectorError: No provider for SiteAdapter!
NullInjectorError: R3InjectorError(CatalogModule)[EffectsFeatureModule -> InjectionToken @ngrx/effects Feature Effects -> [object Object] -> LanguagesEffects -> SiteConnector -> SiteConnector -> SiteAdapter -> SiteAdapter -> SiteAdapter]:
NullInjectorError: No provider for SiteAdapter!
at NullInjector.get (core.js:11120:1)
at R3Injector.get (core.js:11287:1)
at R3Injector.get (core.js:11287:1)
at R3Injector.get (core.js:11287:1)
at injectInjectorOnly (core.js:4770:1)
at Module.ɵɵinject (core.js:4774:1)
at Object.SiteConnector_Factory [as factory] (spartacus-core.js:7506:1)
at R3Injector.hydrate (core.js:11457:1)
at R3Injector.get (core.js:11276:1)
at NgModuleRef$1.get (core.js:25352: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.js:28679:1)
at _ZoneDelegate.invokeTask (zone.js:405:1)
at Zone.runTask (zone.js:178:1)
at drainMicroTaskQueue (zone.js:585:1)
很多 forRoot 方法:
Minor 版本的更改,意味着我们添加了新功能,但它们默认配置为关闭,以免导致兼容性问题。 新的 Minor 版本还意味着包含可能影响兼容性的更改或错误修复,但这些也由功能标志控制。 因此,所有重大变化都是“选择加入(Opt-in)”。
以上是关于将 SAP Spartacus 作为 feature module 进行 Lazy Load 延迟加载时遇到的注入错误分析的主要内容,如果未能解决你的问题,请参考以下文章
SAP Spartacus Definition of Done
关于 SAP Spartacus 重定向部分外部 url 到后台系统的问题
SAP Spartacus Reference App Structure