Ngc error: Compilation failed on ionic build android

Compilation fails during build process whereas application loads fine on ionic serve.

✗ ionic run android 
[10:39:29]  ionic-app-scripts 0.0.23
[10:39:29]  build prod started ...
[10:39:29]  clean started ...
[10:39:29]  clean finished in 16 ms
[10:39:29]  copy started ...
[10:39:29]  ngc started ...
[10:39:29]  copy finished in 270 ms
[10:39:37]  ngc error: Error: Cannot determine the module for component ChatsPage!
at /Users/vishal/Sites/app/node_modules/@angular/compiler/bundles/compiler.umd.js:12963:25
at (native)
at OfflineCompiler.compile (/Users/vishal/Sites/app/node_modules/@angular/compiler/bundles/compiler.umd.js:12959:31)
at /Users/vishal/Sites/app/node_modules/@angular/compiler-cli/src/codegen.js:108:18
at (native)
at CodeGenerator.codegen (/Users/vishal/Sites/app/node_modules/@angular/compiler-cli/src/codegen.js:106:38)
at codegen (/Users/vishal/Sites/app/node_modules/@angular/compiler-cli/src/main.js:7:81)
at Object.main (/Users/vishal/Sites/app/node_modules/@angular/tsc-wrapped/src/main.js:30:16)
at Object.<anonymous> (/Users/vishal/Sites/app/node_modules/@angular/compiler-cli/src/main.js:14:9)
at Module._compile (module.js:541:32)
[10:39:37]  ngc error: Compilation failed

Below is the output of ionic info-

✗ ionic info

Your system information:

Cordova CLI: 6.3.1
Gulp version:  CLI version 1.2.2
Gulp local:  
Ionic Framework Version: 2.0.0-rc.0
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
ios-deploy version: 1.8.5 
ios-sim version: 5.0.6 
OS: Mac OS X El Capitan
Node Version: v6.2.0
Xcode version: Xcode 7.3.1 Build version 7D1014

Did you add ChatsPage to both :
declarations and entryComponents
into app.module.ts


Yes… due to which it loads fine with ionic serve.

I have found the resolution to this issue.

I have a file(pagesMap.ts) where all the page classes are imported and a single constant object(pagesMap) is exported having key as name of component’s class and value as component’s class.

Although importing pagesMap in other pages works fine but the same was not working in app.module.
So importing all the pages in app.module and putting them in declarations and entryComponents worked!