1

I have an Angular application, but I am not understanding what the compiler is telling me on why the application can't build. These are the errors that I'm getting from the compiler:

ERROR in src/app/list-items/list-items.component.ts:9:14 -
error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

Is it missing an @NgModule annotation?

9 export class ListItemsComponent implements OnInit {
               ~~~~~~~~~~~~~~~~~~
src/app/not-found/not-found.component.ts:8:14 - error NG6002: Appears in the NgModule.imports of AppModule, but could
not be resolved to an NgModule class.

Is it missing an @NgModule annotation?

8 export class NotFoundComponent implements OnInit {
               ~~~~~~~~~~~~~~~~~

This is my list-items.component.ts file:

import { Component, OnInit, NgModule } from '@angular/core';

@Component({
  selector: 'app-list-items',
  templateUrl: './list-items.component.html',
  styleUrls: ['./list-items.component.css']
})
export class ListItemsComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
}

This is my not-found.component.ts file:

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

@Component({
  selector: 'app-not-found',
  templateUrl: './not-found.component.html',
  styleUrls: ['./not-found.component.css']
})
export class NotFoundComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
}

Here is my app.module.ts file:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';  
import { ItemService } from './items.service';
import { NewItemFormComponent } from './new-item-form/new-item-form.component';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatButtonModule } from '@angular/material/button';
import { MatMenuModule } from '@angular/material/menu';
import { MatIconModule } from '@angular/material/icon';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { NavigationMenuComponent } from './navigation-menu/navigation-menu.component';
import { ListItemsComponent } from './list-items/list-items.component';
import { NotFoundComponent } from './not-found/not-found.component';
import { BrowserModule } from '@angular/platform-browser';

const appRoutes: Routes = [ {
  path: '',                     //default component to display
   component: ListItemsComponent
 },       {
   path: 'addItem',         //when items added 
   component: NewItemFormComponent
 },       {
   path: 'listItems',       //when items listed
   component: ListItemsComponent
 },       {
   path: '**',                 //when path cannot be found
   component: NotFoundComponent
 }
];

@NgModule({
  declarations: [
    AppComponent,
    NewItemFormComponent,
    NavigationMenuComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    MatFormFieldModule,
    MatInputModule,
    MatButtonModule,
    MatIconModule,
    MatMenuModule,
    BrowserAnimationsModule,
    FormsModule,
    RouterModule.forRoot(appRoutes),
    ListItemsComponent,
    NotFoundComponent
  ],

  providers: [ItemService],
  bootstrap: [AppComponent]
})
export class AppModule { }

Does anyone happen to understand what the compiler is trying to tell me about NgModule?

2
  • Please share the code from your app.modules.ts the error is most likely there. Commented Apr 12, 2020 at 20:36
  • Hi there, added above. Commented Apr 12, 2020 at 20:41

1 Answer 1

4

Remove both components from the imports section in your app.modules file and move them to declarations.

You are not creating a custom module; you are only creating a component. Import it the correct way and you should not have any more problems.

I also suggest you use the angular cli generator to generate new components.

ng generate component test
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.