NullInjectorError: No provider for RouterStateSerializer

Viewed 1705

I've upgraded a little side project from angular 6 to 8 and I am now getting an error that I don't understand.

  StaticInjectorError(Platform: core)[StoreRouterConnectingModule -> RouterStateSerializer]: 
    NullInjectorError: No provider for RouterStateSerializer!
    at NullInjector.get (http://localhost:4200/vendor.js:36416:27)
    at resolveToken (http://localhost:4200/vendor.js:36743:24)
    at tryResolveToken (http://localhost:4200/vendor.js:36669:16)
    at StaticInjector.get (http://localhost:4200/vendor.js:36532:20)
    at resolveToken (http://localhost:4200/vendor.js:36743:24)
    at tryResolveToken (http://localhost:4200/vendor.js:36669:16)
    at StaticInjector.get (http://localhost:4200/vendor.js:36532:20)
    at resolveNgModuleDep (http://localhost:4200/vendor.js:58166:29)
    at _createClass (http://localhost:4200/vendor.js:58243:32)
    at _createProviderInstance (http://localhost:4200/vendor.js:58199:26)

Can someone have a look and give me some pointers. The code can be found here. Thanks in advance!

2 Answers

From 6 to 8, the imports statement for StoreouterConnectingModule changes a little, you need to call forRoot() method as given in ngrx docs here

Code Sample:

import { StoreRouterConnectingModule, routerReducer } from '@ngrx/router-store';
import { AppComponent } from './app.component';

@NgModule({
  imports: [
    BrowserModule,
    StoreModule.forRoot({
      router: routerReducer,
    }),
    RouterModule.forRoot([
      // routes
    ]),
    // Connects RouterModule with StoreModule
    StoreRouterConnectingModule.forRoot(),
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

I Managed to make it work - tough please notice the other answers which explains the nature of the issue and not just a simple "stupid" fix.

open the file cards.module.ts and remove the import of StoreRouterConnectingModule its redundent.. it builds and works perfect.

you are welcome :)

enter image description here

Related