Ionic-app-scripts: Error building Ionic 2 app with --prod flag(Cannot read property 'codeGen' of undefined)

Created on 25 Apr 2017  路  15Comments  路  Source: ionic-team/ionic-app-scripts

Note: for support questions, please use one of these channels:

https://forum.ionicframework.com/
http://ionicworldwide.herokuapp.com/

Short description of the problem:

When I build my Ionic2 application with --prod flag I get the error:

ionic-app-script task: "build"
TypeError: Cannot read property 'codeGen' of undefined
TypeError: Cannot read property 'codeGen' of undefined
at Object.doCodegen (/Users/AresDev/Developer/Yuxi/Brainshark/mobile/brainshark-mobile-app/node_modules/@ionic/app-scripts/dist/aot/codegen.js:6:50)
at /Users/AresDev/Developer/Yuxi/Brainshark/mobile/brainshark-mobile-app/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:42:30

What behavior are you expecting?

That builds works ok

Steps to reproduce:

  1. run command ionic build ios(or android) --prod

Which @ionic/app-scripts version are you using?
Tried several but now using

1.3.4

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

Ionic info:

Cordova CLI: 6.5.0
Ionic Framework Version: 2.0.0-201701301819
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.4
ios-deploy version: 1.9.0
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v6.10.2
Xcode version: Xcode 8.3.2 Build version 8E2002

Any idea, what could be causing this problem?

Most helpful comment

I am running an application on ionic 3 written in ionic2. When I run the command to build android APK without --prod, it is working smoothly. But when I tried to run the same with --prod flag it shows the same error.

Could anybody help me?

All 15 comments

What version of Angular are you running?

Thanks,
Dan

Thank you @danbucholtz I was able to fix it, there was a difference between versions of ionic and Angular. I was using 2.0.0. and in that version, the field __NGTOOLS_PRIVATE_API_2 wasn't present on file packages/compiler-cli/index.ts

BR,
Armando.

@AresDev can you explain a bit more how did you solve the problem?

@AresDev Can you please be a bit more elaborate? Thank you.

@imsrgadich here is what worked for me. I switched to Ionic 2.3.0. and here are my depencies:
"dependencies": { "@angular/common": "2.4.8", "@angular/compiler": "2.4.8", "@angular/compiler-cli": "2.4.8", "@angular/core": "2.4.8", "@angular/forms": "2.4.8", "@angular/http": "2.4.8", "@angular/platform-browser": "2.4.8", "@angular/platform-browser-dynamic": "2.4.8", "@angular/platform-server": "2.4.8", "@ionic-native/camera": "3.7.0", "@ionic-native/core": "3.7.0", "@ionic/cli-plugin-cordova": "1.2.0", "@ionic/cli-plugin-ionic-angular": "1.2.0", "@ionic/storage": "1.1.7", "cordova-android": "^6.2.3", "cordova-common": "2.0.0", "cordova-plugin-camera": "^2.4.1", "cordova-plugin-compat": "^1.1.0", "cordova-plugin-console": "^1.0.5", "cordova-plugin-device": "^1.1.4", "cordova-plugin-file": "^4.3.3", "cordova-plugin-file-transfer": "^1.6.3", "cordova-plugin-splashscreen": "^4.0.3", "cordova-plugin-statusbar": "^2.2.1", "cordova-plugin-whitelist": "^1.3.1", "elementtree": "0.1.7", "ionic-angular": "2.3.0", "ionic-native": "2.4.1", "ionic-plugin-keyboard": "^2.2.1", "ionicons": "3.0.0", "ng2-google-charts": "^2.4.0", "nopt": "4.0.1", "properties-parser": "0.3.1", "q": "1.4.1", "rxjs": "5.0.1", "sw-toolbox": "3.4.0", "zone.js": "0.7.2" }, "devDependencies": { "@ionic/app-scripts": "1.3.7", "@ionic/cli-plugin-cordova": "1.2.1", "@ionic/cli-plugin-ionic-angular": "1.2.0", "typescript": "2.2.0" },

I am running an application on ionic 3 written in ionic2. When I run the command to build android APK without --prod, it is working smoothly. But when I tried to run the same with --prod flag it shows the same error.

Could anybody help me?

@AresDev Can you please reopen it as it is not solved yet?

got the same problem here.

Me too

me too face the same issue.

same here

with @SrdjanStupar tip, it work for me!

I followed instructions at:
https://forum.ionicframework.com/t/guide-how-to-update-to-ionic-3-x/87516

to reinstall all node_modules and updated my dependencies based on a new laravel project so now using ionic/app-scripts: "^2.1.4" and newer versions of ionic and angular than I was using. This fixed the issue and made it past ngc stage of build.

Then new issue "Error: ./node_modules/ionic-native/dist/esm/plugins/plugin.js
Module build failed: TypeError: Cannot read property 'type' of undefined" fixed by removing ... as per instructions at:
https://github.com/ionic-team/ionic/issues/12628

Now --prod build works :)

Hello everyone,
I have solved using npm install, do not need to delete the node_modules.

_NOTE: It worked for me that I was having the same problem._

Guys facing a problem of Cannot read property 'codeGen' of undefined
at Object.doCodegen (F:\geopresence by a_l\version\geopresence_v2\node_modules\@ionic\app-scripts\dist\aot\codegen.js:6:50)
at F:\geopresence by a_l\version\geopresence_v2\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:42:30

Any help

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nalkon picture nalkon  路  4Comments

mburger81 picture mburger81  路  4Comments

danbucholtz picture danbucholtz  路  4Comments

jgw96 picture jgw96  路  3Comments

NoNameProvided picture NoNameProvided  路  4Comments