Angular AOT compilation error "cannot determine module for class Component''

I have actually found a solution. The problem was that PrivateComponent was imported in another file, but not used, just like this:

import { PrivateComponent } from '../private/private.component'; // not used anywhere

Apparently ngc tries to link everything and is confused by an unused import


Make sure you don't accidentally have two files declaring the same component

This often happens to me if I'm in the wrong directory when I run ng g c, and don't immediately delete the wrong generated file.

ERROR in : Cannot determine the module for class FeatureBoxGroupComponent in S:/.../src/app/common-widgets/feature-widgets/feature-box-group/feature-box-group.component.ts! Add FeatureBoxGroupComponent to the NgModule to fix it.

In this example I had FeatureBoxGroupComponent defined in two places:

src\app\common-widgets\feature-widgets\feature-box-group\feature-box-group.component.ts

src\app\feature-widgets\feature-box-group\feature-box-group.component.ts

Of course the error message is telling me the exact file it has a problem with - but it's easy to glance over that.

Just do a find in files for the component name to see everywhere it's referenced and make sure it's only defined once.