Angular No provider for EffectsRootModule錯誤訊息

汪子熙發表於2020-10-11

錯誤訊息:

main.ts:12 NullInjectorError: R3InjectorError(AppModule)[EffectsFeatureModule -> EffectsRootModule -> EffectsRootModule -> EffectsRootModule]:
NullInjectorError: No provider for EffectsRootModule!
at NullInjector.get (http://localhost:4200/vendor.js:62758:27)
at R3Injector.get (http://localhost:4200/vendor.js:76765:33)
at R3Injector.get (http://localhost:4200/vendor.js:76765:33)
at R3Injector.get (http://localhost:4200/vendor.js:76765:33)
at injectInjectorOnly (http://localhost:4200/vendor.js:62613:33)
at Module.ɵɵinject (http://localhost:4200/vendor.js:62623:57)
at Object.EffectsFeatureModule_Factory [as factory] (http://localhost:4200/vendor.js:137576:239)
at R3Injector.hydrate (http://localhost:4200/vendor.js:77003:63)
at R3Injector.get (http://localhost:4200/vendor.js:76753:33)
at http://localhost:4200/vendor.js:76799:25
(anonymous) @ main.ts:12
invoke @ zone-evergreen.js:364
run @ zone-evergreen.js:123
(anonymous) @ zone-evergreen.js:857
invokeTask @ zone-evergreen.js:399
runTask @ zone-evergreen.js:167
drainMicroTaskQueue @ zone-evergreen.js:569
Promise.then (async)
scheduleMicroTask @ zone-evergreen.js:552
scheduleTask @ zone-evergreen.js:388
scheduleTask @ zone-evergreen.js:210
scheduleMicroTask @ zone-evergreen.js:230
scheduleResolveOrReject @ zone-evergreen.js:847
then @ zone-evergreen.js:979
bootstrapModule @ core.js:42679
./src/main.ts @ main.ts:11
webpack_require @ bootstrap:79
0 @ unless.directive.ts:33
webpack_require @ bootstrap:79
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main.js:1

應用程式自己開發的module:


EffectsFeatureModule是dependent type之一:


value是null,所以報錯:

在app.module.ts里加上一行語句即可解決問題:

EffectsModule.forRoot([AppEffects]),

這個forRoot方法為EffectsRootModule提供了可用的provider:

要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":

相關文章