Build with --prod option fails

Hi all !

I am trying to build my project with --prod option and it fails:

 ionic cordova build android --prod --release
[INFO] Running app-scripts build: --prod --platform android --target cordova
       
[14:49:56]  build prod started ... 
[14:49:56]  clean started ... 
[14:49:56]  clean finished in 47 ms 
[14:49:56]  copy started ... 
[14:49:56]  ngc started ... 
TypeError: Cannot read property 'codeGen' of undefined

I found tw other topics about the same issue but no solution seems to have been found. I am building the app on Ubuntu 16.04. This is the output of ionic info:

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.9.2
    ionic (Ionic CLI) : 3.9.2

global packages:

    Cordova CLI : 7.0.1 

local packages:

    @ionic/app-scripts : 1.3.12
    Cordova Platforms  : android 6.2.3
    Ionic Framework    : ionic-angular 3.6.0

System:

    Android SDK Tools : 26.0.2
    Node              : v8.3.0
    npm               : 5.3.0 
    OS                : Linux 4.10

And package.json


{
    "name": "XXXX",
    "author": "XXXX",
    "homepage": "http://ionicframework.com/",
    "private": true,
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
    "dependencies": {
        "@angular/common": "2.2.1",
        "@angular/compiler": "2.2.1",
        "@angular/compiler-cli": "2.2.1",
        "@angular/core": "2.2.1",
        "@angular/forms": "2.2.1",
        "@angular/http": "2.2.1",
        "@angular/platform-browser": "2.2.1",
        "@angular/platform-browser-dynamic": "2.2.1",
        "@angular/platform-server": "2.2.1",
        "@ionic/storage": "2.0.0",
        "cordova-android": "^6.2.3",
        "cordova-plugin-device": "1.1.4",
        "cordova-plugin-network-information": "^1.3.3",
        "cordova-plugin-splashscreen": "~4.0.1",
        "cordova-plugin-statusbar": "2.2.1",
        "cordova-plugin-whitelist": "1.3.1",
        "cordova-sqlite-storage": "^2.0.4",
        "ionic-angular": "^3.6.0",
        "ionic-native": "2.2.11",
        "ionic-plugin-keyboard": "~2.2.1",
        "ionicons": "3.0.0",
        "rxjs": "5.0.0-beta.12",
        "zone.js": "0.6.26"
    },
    "devDependencies": {
        "@ionic/app-scripts": "^1.3.7",
        "typescript": "2.0.9"
    },
    "cordovaPlugins": [
        "cordova-plugin-whitelist",
        "cordova-plugin-console",
        "cordova-plugin-statusbar",
        "cordova-plugin-device",
        "cordova-plugin-splashscreen",
        "ionic-plugin-keyboard"
    ],
    "cordovaPlatforms": [],
    "description": "An Ionic project",
    "cordova": {
        "plugins": {
            "cordova-plugin-device": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {}
        },
        "platforms": [
            "android"
        ]
    }
}

If I build without the --prod option, it works
Thanks for any help.

This is quite old, you should upgrade. Note the breaking changes with 2.x in the changelog.

Please run the same command with --verbose if the error persists.

Thanks for the feedback. I updated with :
npm install @ionic/app-scripts@latest

It is now :

    "devDependencies": {
        "@ionic/app-scripts": "^2.1.4",
        "typescript": "2.0.9"
    },

But the build did no work, here is the verbose output :

 ionic cordova build android --prod --release --verbose
[DEBUG] CLI flags: { interactive: true, confirm: false }
[DEBUG] { cwd: '/home/XXXX/YYYYY', local: false, binPath: 
        '/usr/local/lib/node_modules/ionic/bin/ionic', libPath: 
        '/usr/local/lib/node_modules/ionic/dist/index.js' }
[INFO] Running app-scripts build: --prod --platform android --target cordova
       
[20:29:13]  build prod started ... 
[20:29:14]  clean started ... 
[20:29:14]  clean finished in 1 ms 
[20:29:14]  copy started ... 
[20:29:14]  ngc started ... 
TypeError: Cannot read property 'codeGen' of undefined
[DEBUG] TypeError: Cannot read property 'codeGen' of undefined
            at Object.doCodegen 
        (/home/XXXX/YYYYY/node_modules/@ionic/app-scripts/dist/aot/codegen.js:6:50)
            at 
        /home/XXXX/YYYYY/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:42:30
            at <anonymous>

Thanks for your help

Does it work for a newly created project with ionic start blank blank?

Running the exact same command with a blank project did work. I did not test the build but the output was : “BUILD SUCCESSFUL”. Any idea about what could cause the build to fail ?

Typescript version looks quite old. I would adjust it to match whatever the blank project has.

1 Like

Here how I was able to fix the problem. Updating Typescript was not enought I was still getting the same error.

  • I copy / pasted the package.json file from the blank project into my project
  • Added a couple of dependencies I needed
  • Cleaned npm and installed dependecies from package.json file again
  • Tried to build, got a couple of problems due to new versions of dependencies, fix them
  • Tried to build
  • Grab a coffee
  • BUILD SUCCESSFUL

Thanks for your help