Ionic-app-scripts: Building with --prod causes various issues

Created on 10 Oct 2018  路  5Comments  路  Source: ionic-team/ionic-app-scripts

Short description of the problem:

Whenever I run ionic build --prod or ionic cordova build <platform> --prod I get errors

What behavior are you expecting?

Using the --prod flag should not cause build errors.

Steps to reproduce:

  1. Using the the ionic info supplied below, run ionic build --prod
  2. See the following output
ionic build --prod
> ionic-app-scripts build --prod
[07:33:39]  ionic-app-scripts 3.2.0
[07:33:39]  build prod started ...
[07:33:39]  clean started ...
[07:33:39]  clean finished in 6 ms
[07:33:39]  copy started ...
[07:33:39]  deeplinks started ...
[07:33:40]  deeplinks finished in 346 ms
[07:33:40]  ngc started ...
[07:33:44]  ionic-app-script task: "build"
[07:33:44]  TypeError: Cannot read property 'flags' of undefined
TypeError: Cannot read property 'flags' of undefined
    at checkUnreachable (C:\source\CgMobile\node_modules\typescript\lib\typescript.js:24905:31)
    at bindChildrenWorker (C:\source\CgMobile\node_modules\typescript\lib\typescript.js:23111:17)
    at bindChildren (C:\source\CgMobile\node_modules\typescript\lib\typescript.js:23055:17)
    at bind (C:\source\CgMobile\node_modules\typescript\lib\typescript.js:24319:21)
    at bindSourceFile (C:\source\CgMobile\node_modules\typescript\lib\typescript.js:22689:17)
    at Object.bindSourceFile (C:\source\CgMobile\node_modules\typescript\lib\typescript.js:22640:9)
    at initializeTypeChecker (C:\source\CgMobile\node_modules\typescript\lib\typescript.js:47988:20)
    at Object.createTypeChecker (C:\source\CgMobile\node_modules\typescript\lib\typescript.js:27142:9)
    at getDiagnosticsProducingTypeChecker (C:\source\CgMobile\node_modules\typescript\lib\typescript.js:69678:93)
    at emitWorker (C:\source\CgMobile\node_modules\typescript\lib\typescript.js:69722:32)
[ERROR] An error occurred while running subprocess ionic-app-scripts.

        ionic-app-scripts build --prod exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

Which @ionic/app-scripts version are you using?

Ionic:

   ionic (Ionic CLI)  : 4.2.1
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 ([email protected])
   Cordova Platforms     : android 7.1.1, ios 4.5.5
   Cordova Plugins       : no whitelisted plugins (21 plugins total)

System:

   NodeJS : v10.11.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 10

Most helpful comment

Ok, I've just fixed the problem.
I've downgraded the Ionic CLI from 4.3.1 to 4.2.1

npm uninstall -g ionic
npm install -g [email protected]

Removed packages installed in global cause of a bug in 4.3.1 :
https://github.com/ionic-team/ionic-cli/issues/3729

npm uninstall -g @angular/compiler 
npm uninstall -g @angular/compiler-cli 
npm uninstall -g @ionic/app-scripts

And then install app-scripts and compiler-cli in local

npm install @angular/[email protected]
npm install @ionic/[email protected]

All 5 comments

I have no such error.
It seems like this is not related to ionic-app-scripts itself, but to your application.

Try these:
https://github.com/angular/angular/issues/20794

Can you reproduce this issue on a fresh install?

Exactly same problem here with a new fresh project for test..
I've tested with a fresh ionic4 project and --prod is working :(

> ionic-app-scripts build --prod --target cordova --platform android
[16:03:07]  ionic-app-scripts 3.1.11
[16:03:07]  build prod started ...
[16:03:07]  clean started ...
[16:03:07]  clean finished in 2 ms
[16:03:07]  copy started ...
[16:03:07]  deeplinks started ...
[16:03:07]  deeplinks finished in 24 ms
[16:03:07]  ngc started ...
[16:03:11]  ionic-app-script task: "build"
[16:03:11]  TypeError: Cannot read property 'flags' of undefined
TypeError: Cannot read property 'flags' of undefined
    at checkUnreachable (C:\Users\<username>\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:29004:31)
    at bindChildrenWorker (C:\Users\<username>\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:27023:17)
    at bindChildren (C:\Users\<username>\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:26979:17)
    at bind (C:\Users\<username>\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:28257:21)
    at bindSourceFile (C:\Users\<username>\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:26593:17)
    at Object.bindSourceFile (C:\Users\<username>\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:26534:9)
    at initializeTypeChecker (C:\Users\<username>\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:56480:20)
    at Object.createTypeChecker (C:\Users\<username>\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:30758:9)
    at getDiagnosticsProducingTypeChecker (C:\Users\<username>\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:85043:93)
    at emitWorker (C:\Users\<username>\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:85089:32)
[ERROR] An error occurred while running subprocess ionic-app-scripts.

        ionic-app-scripts build --prod --target cordova --platform android exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

Ionic:

   ionic (Ionic CLI)  : 4.3.1 (C:\Users\<username>\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 ([email protected])
   Cordova Platforms     : android 7.1.2
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.3, (and 5 other plugins)

System:

   Android SDK Tools : 26.1.1 (D:\android-sdk)
   NodeJS            : v10.13.0 (C:\Program Files\nodejs\node.exe)
   npm               : 6.4.1
   OS                : Windows 10

Ok, I've just fixed the problem.
I've downgraded the Ionic CLI from 4.3.1 to 4.2.1

npm uninstall -g ionic
npm install -g [email protected]

Removed packages installed in global cause of a bug in 4.3.1 :
https://github.com/ionic-team/ionic-cli/issues/3729

npm uninstall -g @angular/compiler 
npm uninstall -g @angular/compiler-cli 
npm uninstall -g @ionic/app-scripts

And then install app-scripts and compiler-cli in local

npm install @angular/[email protected]
npm install @ionic/[email protected]

Yes, I also have this config:

Ionic:

   ionic (Ionic CLI)  : 4.1.2 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.0
   Cordova Platforms     : android 6.3.0, browser 5.0.1, ios 4.5.5, osx 4.0.1, windows 5.0.0
   Cordova Plugins       : cordova-plugin-ionic-webview 1.1.1, (and 7 other plugins)

System:

   ios-deploy : 2.0.0
   NodeJS     : v8.11.3 (/usr/local/bin/node)
   npm        : 5.6.0
   OS         : macOS
   Xcode      : Xcode 10.1 Build version 10B61

My problem was fixed only by installing @angular/[email protected].
Thanks @thibaud-sanchez

Was this page helpful?
0 / 5 - 0 ratings