Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullInjectorError: No provider for Compiler

Tags:

angular

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]

like image 305
Alexander Taylor Avatar asked Nov 10 '17 01:11

Alexander Taylor


1 Answers

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

like image 187
Alexander Taylor Avatar answered Oct 03 '22 17:10

Alexander Taylor