NullInjectorError: No provider for e! in Angular 8

Viewed 10736

main-es2015.6f31d328c9edc909ac03.js:1 ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(i)[Se -> e]: StaticInjectorError(Platform: core)[Se -> e]: NullInjectorError: No provider for e!

I get the above error only when I do --prod build. FYI, the module is lazy loaded.

Any suggestions/help will be really appreciated.

3 Answers

Remove all the services from providers as you already have added providedIn: 'root'

OR try this

@NgModule({
    providers: [
        MyService
    ]
})

You have to add your service in app.module.ts

In my case, I had providers:[...] section in one of my components :) When I removed it the error has disappeared.

Hope this might be helpful for someone!

I had a similar problem with the same obscure error message. In my case it was caused by a class which I tought was an Angular service (I didn't write it) . I imported the class and injected it via my component's constructor. Then I got this error message and couldn't figure out why. It turned out that the class I was using was not an Angular service, but a conventional TypeScript class. So I had to instantiate it conventionally (i.e., without Angular's dependency injection):

export class MyComponent {

    // This is what caused my problem. "UtilClass" is no Angular service
    // It can therefore not be injected
    constructor(private util: UtilClass) {}


    // This is the way to use it
    const util = new UtilClass();
    util.doStuff();
}
Related