关于前端:将-SAP-Spartacus-作为-feature-module-进行-Lazy-Load-延迟加载时遇到的注入错误分析

29次阅读

共计 3024 个字符,预计需要花费 8 分钟才能阅读完成。

将 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/manfredste…

增加第 49 行的 OAuthModule.forRoot() 后,谬误隐没:

https://github.com/manfredste…

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)”。

正文完
 0