Angular Compile Error: NG6001: The class is listed in the declarations of the NgModule 'AppModule', but is not a directive, a component, or a pipe

Solution 1:

You have to run npm install when creating new components. Hot reload doesn't seem to be able to add the component.

Solution 2:

I had the same issue. Removing OnInit in the declaration part as well as inside the class helped me. Because it initialized all data-bound properties of the directive. Since this component could have been added in app.module.ts.

export class NavigationMenuItemComponent {
     ....
     ....
     set iconClass(iconClass) {
            this._iconClass = NavigationMenuItemComponent.ID_PREFIX + iconClass;
        }

        //ngOnInit(): void {}
    }

Solution 3:

Add these lines in component:

constructor() {};

ngOnInit(): void {};

I am also facing same issue but I think the error occurs because angular is no more treating it as complete component by adding contructor and ngOnIt have fixed issue.

Solution 4:

When you have multiple error-messages, this error message my show up first.
So make sure to also check the other error messages.

In may case I had a typo in the the tempalteURL (another error message clearly expressed this: NG2008: Could not find template file)