Alexander Taylor
Alexander Taylor

Reputation: 17652

NullInjectorError: No provider for Compiler

Self-answered question for this error:

injector.ts:128 Uncaught Error: StaticInjectorError[Compiler]: StaticInjectorError[Compiler]: NullInjectorError: No provider for Compiler! at _NullInjector.get (injector.ts:23) [angular]

Upvotes: 6

Views: 11900

Answers (1)

Alexander Taylor
Alexander Taylor

Reputation: 17652

I had forgotten to import BrowserModule into my main app module.

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {RouterModule, Routes} from '@angular/router';

import {AppComponent} from './app';
...

@NgModule({
  declarations: [
    AppComponent, ...
  ],
  imports: [
    BrowserModule,  // <-- this!
    RouterModule.forRoot(routes),
  ],
  bootstrap: [
    AppComponent,
  ]
})
export class AppModule {}

If you only see this error during unit testing, see this question: Error: No provider for Compiler! DI Exception Angular 2 Testing

Upvotes: 20

Related Questions