Chandra Shekhar
Chandra Shekhar

Reputation: 16

On Angular 5 ng build command for production I am getting error

my build command ng build --base-href /ProjectFolder/ --deploy-url /ProjectFolder/ --target=production

I am getting below given error, but ng serve is working fine also ng build for development environment is working fine

ERROR in : Type AddManagementAdjComponent in C:/My Drive/Git Project/Elixir/UI/src/app/Feature/add-management-adj/add-management-adj/add-management-adj.component.ts is part of the declarations of 2 modules: AddManagementAdjModule in C:/My Drive/Git Project/Elixir/UI/src/app/Feature/add-management-adj/add-management-adj.module.ts and AddManagementAdjModule in C:/My Drive/Git Project/Elixir/UI/src/app/Feature/add-management-adj/add-management-adj/add-management-adj.module.ts! Please consider moving AddManagementAdjComponent in C:/My Drive/Git Project/Elixir/UI/src/app/Feature/add-management-adj/add-management-adj/add-management-adj.component.ts to a higher module that imports AddManagementAdjModule in C:/My Drive/Git Project/Elixir/UI/src/app/Feature/add-management-adj/add-management-adj.module.ts and AddManagementAdjModule in C:/My Drive/Git Project/Elixir/UI/src/app/Feature/add-management-adj/add-management-adj/add-management-adj.module.ts. You can also create a new NgModule that exports and includes AddManagementAdjComponent in C:/My Drive/Git Project/Elixir/UI/src/app/Feature/add-management-adj/add-management-adj/add-management-adj.component.ts then import that NgModule in AddManagementAdjModule in C:/My Drive/Git Project/Elixir/UI/src/app/Feature/add-management-adj/add-management-adj.module.ts and AddManagementAdjModule in C:/My Drive/Git Project/Elixir/UI/src/app/Feature/add-management-adj/add-management-adj/add-management-adj.module.ts.

I was getting the same error for another component, I delete and recreate that component and error resolved for that particular component but now it is giving me the same error for other components and I cannot recreate all components because I have many such components, Please someone help me

Upvotes: 0

Views: 189

Answers (2)

Taranjit Kang
Taranjit Kang

Reputation: 2580

add-management-adj.component.ts is declared in multiple modules. The production build will pick up all the errors as it's building for optimization.

remove the component from the 2 modules and place within a shareable module or declare in your global module. Then rebuild, also no need for --target=production, just do --prod

Upvotes: 0

Danish Arora
Danish Arora

Reputation: 338

From the error above "is part of the declarations of 2 modules" it seems AddManagementAdjComponent is declared in 2 NgModules, Please check , this May Helpp!!

Upvotes: 1

Related Questions