Platform: Error: No provider for ReducerManager

Created on 18 Aug 2017  路  24Comments  路  Source: ngrx/platform

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[x] Documentation issue or request
[ ] Support request

What is the current behavior?

Error: No provider for ReducerManager

Expected behavior:

No error

Minimal reproduction of the problem with instructions:

I have used the same structure of example-app in this repo

Root module import:
StoreModule.forRoot(reducers, { metaReducers })

Feature module import (from external node_modules)
StoreModule.forFeature('framework', reducers)

Most helpful comment

Just a comment for anyone who comes across this and has the same issue _in their tests_, In my spec file I had to do this:

        TestBed.configureTestingModule({
            imports: [
                ...,
                StoreModule.forRoot({}),
                StoreModule.forFeature('yourFeature', fromFeature.reducers)
            ],

If you remove the forRoot you will get the error.

All 24 comments

Its likely that your feature module import from external node_modules has its own copy of ngrx libraries in its folder, so you're getting two different tokens for the ReducerManager.

@brandonroberts Yeap, added ngrx/store in external rollup config of my library. Thanks!

I ran into the same problem. What is the exact solution?

Hi @vinayakpatil, how did you solve the problem? thanks

I got the same error while testing. Is there a way to check which is the external node_module having its own ngrx libraries?

I too had this problem, my problem was that i was declaring/registering reducer in the app module instead of my child module..!! It should be registered to the corresponding module that has the component and html file.

For me, I got this error when VS Code's automatic import imported StoreModule from '@ngrx/store/src/store_module' instead of '@ngrx/store'. I think this is similar to what @brandonroberts suggested.

@brandonroberts can you provide more information on that error? I have an app with a library that I'm creating. In the app I call StoreModule.forRoot({}) and in a module inside my library I try to create a feature module, which triggers this error.

I've listed ngrx/store and ngrx/entity as externals with rollup and have a small compiled library that doesn't seem to have any ngrx library code in it, yet my library module isn't talking to the app module's store. What could be causing that?

I had the same problem and I found a typo while importing the StoreModule. I had "@ngrx/Store" (capital letter S), replacing by import { StoreModule } from '@ngrx/store'; solved my problem.

Just a comment for anyone who comes across this and has the same issue _in their tests_, In my spec file I had to do this:

        TestBed.configureTestingModule({
            imports: [
                ...,
                StoreModule.forRoot({}),
                StoreModule.forFeature('yourFeature', fromFeature.reducers)
            ],

If you remove the forRoot you will get the error.

@iammikecohen StoreModule.forRoot should only be called once in the root of your project NgModule. If you wan't to register a feature, use StoreModule.forFeature. Using forRoot registers the global providers needed for Store.

I have just come across to the same issue. I am building stand alone components that are using ngrx which will be imported from the node_modules in the apps that have no ngrx. So those apps have accordingly no StoreModule.forRoot(...) So I need to register StoreModule.forRoot before the feature module in the root module otherwise I get the 'No provider for ReducerManager'.
It looks like this:

imports: [ 
    StoreModule.forRoot({}), // Without this declaration it throws ReducerManager error
    StoreModule.forFeature('yourFeature', fromFeature.reducers)
 ]

I guess this is an issue...

I got this error because VS Code created a wrong import statement. Instead of

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

it was

import { Store } from '@ngrx/store/something more';

I had the same issue as @haldunatar and solved this by adding StoreModule.forRoot({}) to my app.module.ts file. Works by adding it above the .forFeature also but just the way I have my structure set up.

Hi
I had same issue resolved by StorreModule.forFeature('name', {reducer})
In my case I missed { } for reducer array

I am just wondering; If we are giving a global library, and the user has not ngrx installed then what happens?

I had the same problem, we are writing a library that creates feature Store and Effects.

I was able to solve this by setting the paths in my tsconfig.app.json in the In the consuming app.

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "paths": {
      "@angular/*": ["../node_modules/@angular/*"],
      "@ngrx/*": ["../node_modules/@ngrx/*"]
    },
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

@RyanLynnWood you is my hero!
I'm implementing project with ngrx and import another project with ngrx as dependency. Your solution works for me.

@haldunatar
Your solution works well with a little difference for me:
i use in my feature module like following:
StoreModule.forFeature('user', reducers, { metaReducers }),
StoreModule.forRoot({})

Try to move @ngrx/store into peerDependencies in package.json of library. Seems like your library installs its own @ngrx/store.

I started getting this when upgrading to angular 9. I've got a framework angular app with a couple libraries, and an application angular app that uses tsconfig.json paths in the app to point to the libraries from the framework.

I had to add The tsconfig.json paths fix to the consuming application like others have mentioned, but I had to do it for several libraries that are used in both the framework and the application:

  "paths: {
      "@angular/*": [ "./node_modules/@angular/*" ],
      "@ngrx/*": [ "./node_modules/@ngrx/*" ],
      "ngx-bootstrap": [ "./node_modules/ngx-bootstrap" ],
      "angularx-social-login": [ "./node_modules/angularx-social-login" ],
  }

I had the same problem and my solution was the same @haldunatar recommended

 imports: [
       StoreModule.forRoot({}), 
    StoreModule.forFeature('filter-app', filterReducer)
],

I started getting this when upgrading to angular 9. I've got a framework angular app with a couple libraries, and an application angular app that uses tsconfig.json paths in the app to point to the libraries from the framework.

I had to add The tsconfig.json paths fix to the consuming application like others have mentioned, but I had to do it for several libraries that are used in both the framework and the application:

  "paths: {
      "@angular/*": [ "./node_modules/@angular/*" ],
      "@ngrx/*": [ "./node_modules/@ngrx/*" ],
      "ngx-bootstrap": [ "./node_modules/ngx-bootstrap" ],
      "angularx-social-login": [ "./node_modules/angularx-social-login" ],
  }

@jonstelly
This solution worked for me. Thank you!

Just a quick note, you can get this error when you create a feature Module with its own Store that calls StoreModule.forFeature(whatever), and not having imported StoreModule.forRoot({}) in the app.module.

Was this page helpful?
0 / 5 - 0 ratings