Angular 5: ERROR Error: The selector "app-root" did not match any elements

I've checked and compiled 12 times now and can't seem to figure out why I'm getting this error in my console:

ERROR Error: The selector "app-root" did not match any elements
at e.selectRootElement (main.bundle.js:1)
at Sn (main.bundle.js:1)
at zr (main.bundle.js:1)
at Lr (main.bundle.js:1)
at Object.io [as createRootView] (main.bundle.js:1)
at t.create (main.bundle.js:1)
at t.create (main.bundle.js:1)
at e.bootstrap (main.bundle.js:1)
at main.bundle.js:1
at Array.forEach (<anonymous>)

Index.html

<body>
  <app-root></app-root>
</body>

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';

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

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
        HttpModule
      ],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'App Component';
}

I've read through several others who experienced this error and it was usually due to the index.html file not using the correct selector name. I've checked my code and it looks correct to me.

1 answer

  • answered 2018-02-13 01:08 raja reddy

    Added a working plunker, From 4.3.x HttpModule available as HttpClientModule at '@angular/common/http'