Whenever I execute ng build project1 --prod
, the build fails and displays this error message:
.ERROR in : Cannot determine the module for class MyComponent in .../project2/app/my.component.ts! Add MyComponent to the NgModule to fix it.
Although the solution seems obvious, there's a twist. The Component mentioned is not part of the current Angular project. I have two separate projects defined in my angular.json file - project1 and project2. These projects are independent of each other but share a common module that both projects import and utilize.
The error surfaced when I relocated a component from project2 to the shared module. Project2 compiles successfully and the moved components function correctly. Running ng serve project1
doesn't pose any issues. However, inexplicably, my first project now appears to depend on several components from the second project. I have meticulously searched all imports for the aforementioned file without luck. It's possible that this anomaly is linked to the fact that the components from project2 extend a component from the shared module.
Is there a method to identify why Angular believes it needs this component? For instance, can I pinpoint what Angular is attempting to compile when the error occurs?
Is it feasible to exclude this element somehow (the tsconfig.app.json
exclude parameter didn't yield results)?