TypeError: Cannot read property 'runOutsideAngular' of undefined

Hi there, I am working in an app with Ionic 4, and everything works fine with ionic serve, ionic cordova run browser and ionic cordova run android, but when I add --prod --release I get this error and I cannot identify what is wrong.

This is my Ionic info:


Ionic CLI : 5.2.4 (C:\Users\XXXX\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.7.1
@angular-devkit/build-angular : 0.801.3
@angular-devkit/schematics : 8.1.3
@angular/cli : 8.1.3
@ionic/angular-toolkit : 2.0.0


Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : not available
Cordova Plugins : not available


cordova-res : 0.4.0
native-run : 0.2.2


Android SDK Tools : 26.1.1 (C:\Users\XXXX\AppData\Local\Android\Sdk)
NodeJS : v10.16.0 (C:\Program Files\nodejs\node.exe)
npm : 6.9.0
OS : Windows 10

SOLVED: In my case, I had go disable aot and buildOptimizer from angular.json file.

angular.json > app > architect > build > configurations > production

Set “aot”: false
Set “buildOptimizer”: false


ionic cordova run android --prod --release

I hope it helps.

I would instead work to fix the underlying problem, because turning off aot is likely to be a big performance hit.

I agree. I shouldn’t disable aot, but that was the only solution I found. I think it will work until I find a true fix for the underlying problem.