Build Error in ionic


#1

I have created an app using ionic v3
but trying to build the apk file CLI through an error

mysangham is my project name

I have used
ionic cordova run android to run the application in stimulator and it works fine

but
i used these command in CLI
ionic cordova run android --prod --release or ionic cordova build android --prod --release
it shows the following error

Running app-scripts build: --prod --platform android --target cordova
[15:57:12] build prod started …
[15:57:12] clean started …
[15:57:12] clean finished in 7 ms
[15:57:12] copy started …
[15:57:12] deeplinks started …
[15:57:12] deeplinks finished in 66 ms
[15:57:12] ngc started …
Error: Type ChapterPage in D:/Projects/ionic project/mySangham/android/src/pages
/chapter/chapter.ts is part of the declarations of 2 modules: AppModule in D:/Pr
ojects/ionic project/mySangham/android/src/app/app.module.ts and ChapterPageModu
le in D:/Projects/ionic project/mySangham/android/src/pages/chapter/chapter.modu
le.ts! Please consider moving ChapterPage in D:/Projects/ionic project/mySangham
/android/src/pages/chapter/chapter.ts to a higher module that imports AppModule
in D:/Projects/ionic project/mySangham/android/src/app/app.module.ts and Chapter
PageModule in D:/Projects/ionic project/mySangham/android/src/pages/chapter/chap
ter.module.ts. You can also create a new NgModule that exports and includes Chap
terPage in D:/Projects/ionic project/mySangham/android/src/pages/chapter/chapter
.ts then import that NgModule in AppModule in D:/Projects/ionic project/mySangha
m/android/src/app/app.module.ts and ChapterPageModule in D:/Projects/ionic proje
ct/mySangham/android/src/pages/chapter/chapter.module.ts.
at Error (native)
at syntaxError (D:\Projects\ionic project\mySangham\android\node_modules@an
gular\compiler\bundles\compiler.umd.js:1729:34)
at CompileMetadataResolver._addTypeToModule (D:\Projects\ionic project\mySan
gham\android\node_modules@angular\compiler\bundles\compiler.umd.js:15728:31)
at D:\Projects\ionic project\mySangham\android\node_modules@angular\compile
r\bundles\compiler.umd.js:15616:27
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (D:\Projects\ionic project\my
Sangham\android\node_modules@angular\compiler\bundles\compiler.umd.js:15607:54)

at addNgModule (D:\Projects\ionic project\mySangham\android\node_modules\@an

gular\compiler\bundles\compiler.umd.js:24403:58)
at D:\Projects\ionic project\mySangham\android\node_modules@angular\compile
r\bundles\compiler.umd.js:24414:14
at Array.forEach (native)
at _createNgModules (D:\Projects\ionic project\mySangham\android\node_module
s@angular\compiler\bundles\compiler.umd.js:24413:26)
[15:57:14] copy finished in 2.15 s

Please help


#2

There is you error. If you use lazy loading, remove the reference in AppModule, if you don’t use lazy module, remove chapter.module.ts


#3

But if i remove this i will show an error in the normal run method "ionic cordova run android "


#4

No

Running the cmd with --prod add extra checks which are not performed for example when you run ionic serve
This means that you face there the error too, it is just not shown