angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Can not determine the module class x Component in location/x.component.ts add xcomponent to Ng Module to fix it. Angular 4

Open bisho012 opened this issue 9 years ago • 22 comments

I am not on the production phase on my web ... the project is working good ... I used

ng serve --o
ng build 

and it is working great .... then I tried :-

ng build --prod

this error appeared

 Cannot determine the module for class CategoriesComponent in C:/project/src/app/Components/categories/categories.component.ts! Add CategoriesComponent to the NgModule to fix it.

I know that I made a mistake ... I made 2 components with the same name but I removed the wrong one.

and here is the code of app.Module.ts file :-

    import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule , Routes } from '@angular/router';

import { FormsModule } from '@angular/forms';
import { FlashMessagesModule } from 'angular2-flash-messages';

import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabase } from 'angularfire2/database';
import { AngularFireAuth } from 'angularfire2/auth';

import { AppComponent } from './app.component';
import { OrdersComponent } from './Components/orders/orders.component';
import { ItemsComponent } from './Components/items/items.component';
import { NavbarComponent } from './Components/navbar/navbar.component';
import { LoginComponent } from './Components/login/login.component';
import { RegisterComponent } from './Components/register/register.component';

import { OrdersService } from './services/orders.service';
import { AdditemsService } from './services/additems.service';
import { AddcategoriesService } from './services/addcategories.service';
import { LoginService } from './services/login.service';
import { RegisterService } from './services/register.service';
import { AddresturantService } from './services/addresturant.service';

import { AllordersComponent } from './components/allorders/allorders.component';
import { CategoriesComponent } from './components/categories/categories.component';
import { RestaurantsComponent } from './Components/restaurants/restaurants.component';


const appRoutes: Routes = [
  {path: '', component: OrdersComponent},
  {path: 'register', component: RegisterComponent},
  {path: 'login', component: LoginComponent},
  {path: 'items', component: ItemsComponent},
  {path: 'categories', component: CategoriesComponent},
  {path: 'restaurants', component: RestaurantsComponent}
];

export const firebaseConfig = {
 
};

@NgModule({
  declarations: [
    AppComponent,
    OrdersComponent,
    ItemsComponent,
    NavbarComponent,
    LoginComponent,
    RegisterComponent,
    AllordersComponent,
    CategoriesComponent,
    RestaurantsComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    FlashMessagesModule,
    AngularFireModule.initializeApp(firebaseConfig),
    RouterModule.forRoot(appRoutes)
  ],
  providers: [
    AngularFireDatabase,
    AngularFireAuth,
    OrdersService,
    AdditemsService,
    AddcategoriesService,
    LoginService,
    RegisterService,
    AddresturantService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

I removed the component that was wrong and left the right one. What shall I do to make the production accept these components !

any suggestions ?

bisho012 avatar Oct 15 '17 18:10 bisho012

I too am experiencing this problem.

We are using 1.5.0 for the CLI on Windows 10 x64

mrunks avatar Nov 03 '17 15:11 mrunks

Subscribing. I've encountered the same issue with ng build --prod, but not on ng serve. See this thread, too: https://github.com/angular/angular/issues/13590

markfullmer avatar Dec 24 '17 00:12 markfullmer

i have resolved this issue by removing multiple component classes with the same name.

shaukatwaqarangular avatar Apr 26 '18 14:04 shaukatwaqarangular

I have fixed it just by matching the import statement with casing on the file name.

image File name: communityInformation.component.ts

sundeepyama avatar May 14 '18 20:05 sundeepyama

Thx. I had the same problem with also was caused by file casing

Anderman avatar Jul 10 '18 22:07 Anderman

I had to remove a duplicate component class that wasn't declared in @NgModule. The fact that it wasn't imported and declared in the ngModule allowed ng serve to work.

e5enrico avatar Aug 29 '18 01:08 e5enrico

My component was not in app.module.ts declarations. (Thought it would be excluded though.)

gwest7 avatar Sep 07 '18 08:09 gwest7

I don't have multiple class with the same name and casing also is fine but still, I am getting this error.

yedidisatya avatar Nov 26 '18 08:11 yedidisatya

I had the same error caused by a pipe that I forgot to declare in a module. In dev it works fine without declaring. This wasn't happening in Angular 6, but happens in 7

johnnysainz avatar Jan 03 '19 16:01 johnnysainz

My component was not in app.module.ts declarations. (Thought it would be excluded though.)

this fixed it for me as well. The component was not included in the app.module.ts file imports

waqasraza123 avatar Feb 04 '19 20:02 waqasraza123

I also having the same error: ERROR in : Cannot determine the module for class CCURLActionComponent in C:/Users/HP/Desktop/default-2/default/src/app/content/pages/header/action/aslaAction/aslaActionURL/asla-url-action.component.ts! Add CCURLActionComponent to the NgModule to fix it.

how to solve this error.

ShrJoshi28 avatar Mar 27 '19 11:03 ShrJoshi28

I also resolved this by fixing casing in an import statement. However, in my case the casing error was not in the app.module.ts file, but in one of the guards. So be sure to check the import casing in ALL the ts files in the project!

bjowes avatar Mar 28 '19 16:03 bjowes

I fixed this error by moving some export interface IModel..... from a component file to a dedicated file for models. It appears like the compiler/trans-piler saw the component as not being declared in any NgModule, even though the component was not used.

My project structure is multiple projects, and it was only causing the failure in the projects that were not using the component in question.

I also having the same error: ERROR in : Cannot determine the module for class CCURLActionComponent in C:/Users/HP/Desktop/default-2/default/src/app/content/pages/header/action/aslaAction/aslaActionURL/asla-url-action.component.ts! Add CCURLActionComponent to the NgModule to fix it.

how to solve this error.

joshvito avatar Apr 24 '19 14:04 joshvito

I have the same error but I don't have any duplicate's and using the same file naming convention everywhere. I am lazy loading my components so they are not in the app.module.

everywhere I do the same thing but at this specific component, it doesn't work.

when I get rid of the link in the module it creates the same error twice.

D252874 avatar May 15 '19 10:05 D252874

I had the same error because I changed the folder name (upper case) to (lower case). It was working fine with ng serve and ng build but give error when I tried to build for production. I change the folder name in import statement on module file and it fixed the issue for me.

RaviKumar1611 avatar May 28 '19 01:05 RaviKumar1611

I had the same problem, Folder name casing was the reason for this .

NIHAR-SARKAR avatar Aug 20 '19 14:08 NIHAR-SARKAR

solved this issue by removing a duplicate of same component

SaliZumberi avatar Aug 27 '19 11:08 SaliZumberi

I have the same issue with an Abstract component.

siddharthagit avatar Aug 31 '19 07:08 siddharthagit

I still have this issue. I created another project and add only the components which giving this error and guess what?! Still same issue.

I even switched the components name to A,B, C and D, still same issue. Why always angular build in production mode it's painful? Every time when I add an new component it's same issue and after some time I try build with prod randomly and works. What's the problem with angular?

Messhias avatar Sep 03 '19 05:09 Messhias

User has added CategoriesComponent in two place means two different file have same registration in module. First search and delete one place entry and rebuild again for pointing to prod

Error : Cannot determine the module for class CategoriesComponent in C:/project/src/app/Components/categories/categories.component.ts! Add CategoriesComponent to the NgModule to fix it.

100% working for me

gtmtech-pro avatar Sep 24 '19 08:09 gtmtech-pro