Can't build apk after update to latest version

After update ionic and Cordova to latest, everything gone mad.
All my projects are unable to build.
When running ionic cordova build android --prod --release and got errors:

Error: Cannot find module ‘@angular/compiler-cli/ngtools2’
An error occurred while running subprocess ionic-app-scripts.

ionic-app-script task: “build”
Error: Cannot find module ‘@angular/compiler-cli/ngtools2’
Error: Cannot find module ‘@angular/compiler-cli/ngtools2’
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at /Users/xxxxxxx/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:206:90
[ERROR] An error occurred while running subprocess ionic-app-scripts.
code ENOLOCAL
ERR! Could not install from “@angular/compiler-cli/ngtools2” as it does not contain a package.json file.

Try running npm install @angular/compiler-cli/ngtools2 and got below error:
Could not install from “@angular/compiler-cli/ngtools2” as it does not contain a package.json file.

Already tried remove node_module folder, run npm install and rebuild node-sass. All not working.

If I run ionic cordova build android --release (without --prod), the apk file can be built, but the apk file is so big.

My environment:

Ionic:
ionic (Ionic CLI) : 4.10.3 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.9
@ionic/app-scripts : 3.2.4

Cordova:
cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 7.0.0, ios 4.5.4
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.0, (and 17 other plugins)

Some please help me, is it the environment problem, or plugin, or others?
Thanks in advance.

package.json likely relevant.

Hi, please give me more detail. Thank you.

Tried so many days, still can’t find solution.
If I run ionic cordova build android --release (without --prod), the apk file is built, but the file is so big.
Somebody help!!

Facing the same issue here is my package.json , Ionic serve is fine no error, ionic cordova build android --prod --release fails with bellow error

[00:35:35]  ionic-app-script task: "build" 
[00:35:35]  Error: Cannot find module '@angular/compiler-cli/ngtools2' Require stack: - 
            /media/peter/Media/projects/v3/stockappadmin/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js - 
            /media/peter/Media/projects/v3/stockappadmin/node_modules/@ionic/app-scripts/dist/ngc.js - 
            /media/peter/Media/projects/v3/stockappadmin/node_modules/@ionic/app-scripts/dist/build.js - 
            /media/peter/Media/projects/v3/stockappadmin/node_modules/@ionic/app-scripts/dist/index.js - 
            /media/peter/Media/projects/v3/stockappadmin/node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js 
Error: Cannot find module '@angular/compiler-cli/ngtools2'
Require stack:
- /media/peter/Media/projects/v3/stockappadmin/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js
- /media/peter/Media/projects/v3/stockappadmin/node_modules/@ionic/app-scripts/dist/ngc.js
- /media/peter/Media/projects/v3/stockappadmin/node_modules/@ionic/app-scripts/dist/build.js
- /media/peter/Media/projects/v3/stockappadmin/node_modules/@ionic/app-scripts/dist/index.js
- /media/peter/Media/projects/v3/stockappadmin/node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at /media/peter/Media/projects/v3/stockappadmin/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:206:90

{
  "name": "myapp",
  "version": "0.0.1",
  "author": "me",
  "homepage": "http://me.app/",
  "private": true,
  "scripts": {
    "start": "ionic-app-scripts serve",
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/animations": "5.2.11",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "^9.0.7",
    "@angular/core": "5.2.11",
    "@angular/forms": "5.2.11",
    "@angular/http": "5.2.11",
    "@angular/platform-browser": "5.2.11",
    "@angular/platform-browser-dynamic": "5.2.11",
    "@ionic-native/app-update": "^4.20.0",
    "@ionic-native/call-number": "^4.20.0",
    "@ionic-native/core": "~4.18.0",
    "@ionic-native/native-audio": "^4.20.0",
    "@ionic-native/photo-library": "^5.8.0",
    "@ionic-native/push": "^4.20.0",
    "@ionic-native/splash-screen": "~4.18.0",
    "@ionic-native/status-bar": "~4.18.0",
    "@ionic/storage": "2.2.0",
    "@swimlane/ngx-datatable": "^15.0.2",
    "@types/html2canvas": "0.0.35",
    "@types/jspdf": "^1.3.0",
    "angular-datatables": "^8.0.0",
    "call-number": "^1.0.1",
    "chart.js": "^2.8.0",
    "cordova-android": "8.1.0",
    "cordova-android-support-gradle-release": "^3.0.1",
    "cordova-browser": "5.0.4",
    "cordova-plugin-app-update": "^2.0.2",
    "cordova-plugin-appversion": "^1.0.0",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-file": "^6.0.1",
    "cordova-plugin-file-opener2": "^2.1.4",
    "cordova-plugin-ionic-keyboard": "^2.1.3",
    "cordova-plugin-ionic-webview": "^2.5.1",
    "cordova-plugin-nativeaudio": "^3.0.9",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-support-google-services": "^1.3.2",
    "datatables.net": "^1.10.19",
    "datatables.net-dt": "^1.10.19",
    "firebase": "^6.3.5",
    "html2canvas": "^1.0.0-rc.3",
    "ionic-angular": "3.9.2",
    "ionic-select-searchable": "^2.10.0",
    "ionic-selectable": "^3.4.2",
    "ionic2-super-tabs": "^5.2.0",
    "ionic3-calendar-en": "^1.1.3",
    "ionicons": "3.0.0",
    "jodit": "^3.2.45",
    "jquery": "^3.4.1",
    "moment": "^2.24.0",
    "mx.ferreyra.callnumber": "~0.0.2",
    "ngx-pipes": "^2.5.1",
    "node-sass": "^4.13.0",
    "phonegap-plugin-multidex": "^1.0.0",
    "phonegap-plugin-push": "^2.3.0",
    "rxjs": "6.0.0",
    "rxjs-compat": "6.0.0",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-optimizer": "^0.12.4",
    "@ionic/lab": "^3.1.2",
    "@types/datatables.net": "^1.10.17",
    "@types/jquery": "^3.3.30",
    "@ionic/app-scripts": "3.2.4",
    "typescript": "~2.6.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-android-support-gradle-release": {
        "ANDROID_SUPPORT_VERSION": "27.+"
      },
      "cordova-plugin-app-update": {},
      "cordova-plugin-file-opener2": {
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      },
      "cordova-plugin-file": {},
      "cordova-plugin-nativeaudio": {},
      "mx.ferreyra.callnumber": {},
      "phonegap-plugin-push": {}
    },
    "platforms": [
      "browser",
      "android"
    ]
  }
}

This looks like your biggest problem. I would push this back to 5.2.11 to match the rest of your Angular kit.

Secondarily,

…is also going to be a problem. All @ionic-native/* stuff must be aligned on the same major version, so I would push this back to whatever the last 4.x is.

These also concern me. I just peeked at an old project of mine that has roughly your Angular dependencies, and it’s using rxjs 5.5.12. Angular, RxJS, and Zone.js are all very tightly coupled, and do not take kindly to having their known compatible versions jostled around.

2 Likes