3

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!

wendellmva
  • 1,896
  • 1
  • 26
  • 33
  • did you upgrade ngrx as well? – Reza Jun 26 '19 at 13:13
  • I recreated the project using create-nx-workspace so I assume ngrx 8 is the correct version that goes along with angular 8 – wendellmva Jun 26 '19 at 13:24
  • did you import the modules correctly, because this error means one of the classes needs `RouterStateSerializer` and it's not provided, it could be your classes or one of the dependecies, I would suggest to go through the ngrx docs again and make sure you imported the modules correctly. (btw you mentioned you upgraded a project but seems you recreated a new one, this is misleading ;) ) – Reza Jun 26 '19 at 13:27

2 Answers2

8

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 {}
Ganapat
  • 6,984
  • 3
  • 24
  • 38
2

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

Kashkashio
  • 487
  • 5
  • 10
  • 1
    Although accepted as the answer for this question, removing the import should not be considered a "fix" to the problem. The second answer to this question https://stackoverflow.com/a/57465624/1084306 with more upvotes should be the accepted as it actually gives context into why there is an error and what the "actual" fix is. This is especially important in the case of people who actually NEED to use the import and in my case it came from an upgrade which the below answer solves the problem. – Donovan Sep 06 '20 at 20:09
  • Thank you for elaborating tough the questions wasn't on how this thing works. the case is different. there is a package/library that people can't find a way to make them work. a small hint to make it work might be considered as a solution but yes i can definetly relate to what you wrote and i'l be okay with the accepted answer being changed :D – Kashkashio Sep 07 '20 at 11:14
  • 1
    There should not be anything needed to "make work" in this case since due to the updated code, the syntax being used would never work. Removing any plugin would remove errors related to that plugin removed and should never be considered a "fix" or "solution". If someone (like myself) is actually having the problem in this question, your answer would not help them at all. That is the only reason i pointed out the actual comment that fixed the problem for me, so that anyone in the future doesn't see your answer and give up on looking. – Donovan Sep 09 '20 at 20:10
  • You're awesome @Kashkashio – Donovan Sep 17 '20 at 21:04