Ionic5 prod build fails

Hi all,

ionic info

Ionic:

   ionic (Ionic CLI)             : 4.12.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 5.0.0
   @angular-devkit/build-angular : 0.801.3
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.1.2

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : none
   Cordova Plugins       : no whitelisted plugins (0 plugins total)

System:

   Android SDK Tools : 26.1.1 (/Users/lucascrivelli/Library/Android/sdk)
   ios-deploy        : 1.9.4
   NodeJS            : v10.16.1 (/usr/local/bin/node)
   npm               : 6.9.0
   OS                : macOS
   Xcode             : Xcode 10.3 Build version 10G8

After successfully migrated my app to Ionic v5, I wanted to build it for testing on real device:

ionic cordova build ios --release --prod

but that failed with the following error:

ERROR in ./node_modules/@ionic/angular/fesm2015/ionic-angular.js
Module build failed (from ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js):
TypeError: Cannot read property 'kind' of undefined
    at isAngularDecoratorMetadataExpression (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/@angular-devkit/build-optimizer/src/transforms/scrub-file.js:265:35)
    at checkNodeForDecorators (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/@angular-devkit/build-optimizer/src/transforms/scrub-file.js:77:21)
    at visitNodes (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/typescript/lib/typescript.js:16514:30)
    at Object.forEachChild (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/typescript/lib/typescript.js:16740:24)
    at checkNodeForDecorators (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/@angular-devkit/build-optimizer/src/transforms/scrub-file.js:68:31)
    at visitNode (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/typescript/lib/typescript.js:16505:24)
    at Object.forEachChild (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/typescript/lib/typescript.js:16635:21)
    at checkNodeForDecorators (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/@angular-devkit/build-optimizer/src/transforms/scrub-file.js:68:31)
    at visitNode (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/typescript/lib/typescript.js:16505:24)
    at Object.forEachChild (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/typescript/lib/typescript.js:16703:24)
    at checkNodeForDecorators (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/@angular-devkit/build-optimizer/src/transforms/scrub-file.js:68:31)
    at visitNode (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/typescript/lib/typescript.js:16505:24)
    at Object.forEachChild (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/typescript/lib/typescript.js:16692:24)
    at checkNodeForDecorators (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/@angular-devkit/build-optimizer/src/transforms/scrub-file.js:68:31)
    at visitNode (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/typescript/lib/typescript.js:16505:24)
    at Object.forEachChild (/Users/lucascrivelli/Desktop/APP/ionic/connexxion/node_modules/typescript/lib/typescript.js:16599:21)
[ERROR] An error occurred while running subprocess ng.
        
        ng run app:ionic-cordova-build:production --platform=android exited with exit code 1.
        
        Re-running this command with the --verbose flag may provide more information.

Did I miss something for the migration? Anyone else experiencing the same issue?

Side note:

  • ionic serve works great
  • Build works when downgrading @ionic/angular to 4.7.1

Thanks for your support.

Cheers,
Lucas

You seem to use a very old Version of the Ionic CLI. Try upgrading it:

npm uninstall -g ionic
npm install -g @ionic/cli

Thanks @EinfachHans but still the same problem after upgrading ionic/cli

> ionic info

Ionic:

   Ionic CLI                     : 6.1.0 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.0.0
   @angular-devkit/build-angular : 0.801.3
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.1.2

Cordova:

   Cordova CLI       : 8.0.0
   Cordova Platforms : none
   Cordova Plugins   : no whitelisted plugins (0 plugins total)

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   Android SDK Tools : 26.1.1 (/Users/lucascrivelli/Library/Android/sdk)
   ios-deploy        : 1.9.4
   NodeJS            : v10.16.1 (/usr/local/bin/node)
   npm               : 6.9.0
   OS                : macOS Catalina
   Xcode             : Xcode 10.3 Build version 10G8

had same problem, try updating dependencies as this issue says:
https://github.com/ionic-team/ionic/issues/20341

4 Likes

Hi, you can use --aot instead of --prod like:
ionic cordova build android --aot

1 Like

@galler’s suggestion of updating @angular/devkit stuff is much better than @Hammad6264’s post that is currently marked as the “solution” here. See this issue for additional information.

Using --aot instead of --prod is basically nerfing the build instead of addressing the actual issue.

That was it. Thank you very much @galler!

Thanks @rapropos for clarifying this. Indeed It seems much better to update the dependencies than to use --aot (which is not even part of the help).