9

When migrating my project from @ngrx 2.x to 4.1.0, I encountered the error message

NullInjectorError: No provider for Store!

The store was imported as shown in the docs:

import { StoreModule as NgRxStoreModule } from '@ngrx/store';

@NgModule({
  imports: [
    NgRxStoreModule.forRoot(reducerMap, {
      initialState: initial
    }),
    StoreRouterConnectingModule,
    EffectsModule.forRoot(effects)
  ],
  providers: [AppActions]
})
export class StoreModule {}
Anton Poznyakovskiy
  • 2,109
  • 1
  • 20
  • 38

3 Answers3

11

Turned out that some of my services imported the store via

import { Store } from '@ngrx/store/src/store'

Changing the imports to

import { Store } from '@ngrx/store'

fixed the problem.

Anton Poznyakovskiy
  • 2,109
  • 1
  • 20
  • 38
0

I got this while I was trying to run tests in angular 7.

The solution for me was to:

  1. define a store mock in the body of describe:
let storeMock;
  1. initialize it in beforeEach section:
  beforeEach(async () => {
    storeMock = {
      dispatch: jasmine.createSpy("dispatch"),
      pipe: jasmine.createSpy("pipe").and.returnValue(from([{
...
        requestTimeout: 5000,
...
      }]))
    };
  1. define provider for Store in TestBed.configureTestingModule:
    TestBed.configureTestingModule({
      imports: [
        HttpClientTestingModule,
      ],
      providers: [
        ...
        {
          provide: Store,
          useValue: storeMock
        }
        ...
      ]
    });
    ```
uthomas
  • 677
  • 2
  • 9
  • 17
0

For ngrx 8 use:

import { provideMockStore } from '@ngrx/store/testing';
Gal Margalit
  • 5,525
  • 6
  • 52
  • 56