Can't get rid of JIT after upgrade Angular7.2/Ionic 4 to Angular 10/Ionic5

Hi

I went through the upgrade steps as documented by angular.io and ionic, to move my Angular 7.2/Ionic 4 app to Angular 10/Ionic 5. Unfortunately, I still need to import '@angular/compiler'; in main.ts otherwise the browser console.log complains about compiler not present and the app does not run. So I am running JIT whereas the docs says it should be AOT - seemingly.

I tried to compare angular.json of a new a10/I5 project but cant see the key differences. main.ts is the same except for the import of the compiler.

How can I get rid of the angular compliler and truly run aot (even though it says aot:true)?

Steps I took to upgrade:

Go to Angular 8

  1. change tsconfig.json -> "module": "esnext",
  2. ng update @angular/cli@8 @angular/core@8
  3. As the routes are not migrated to dynamic imports, I run:
  4. ng update @angular/cli --from 7 --to 8 --migrate-only
  5. ng update @angular/core --from 7 --to 8 --migrate-only

Update latest Ionic 4 to see deprecated warnings:
6. npm i @ionic/angular@4.11.10 --save (coming from 4.1.0)

Get rid of security warnings:
7. npm audit fix (not earlier)

Go Ionic 5:
8. npm install @ionic/angular@latest @ionic/angular-toolkit@latest --save
9. Fix the breaking changes as per Ionic docs

EDIT: I overlooked breaking changes in Angularfire going to Angular 9 - Angularfire will go to 6. These steps not noted here, but necessary!

Go to Angular 9:
10. Remove any es5BrowserSupport flags in your angular.json (as per update.angular.io)
11. ng update @angular/cli@9 @angular/core@9
12. Add zone-flags.ts in files section of tsconfig.app.json
13. Add allowedCommonJsDependencies in angular.json
14. import '@angular/compiler'; in main.ts so the app does not break anymore

Go to Angular 10:
15. ng update @angular/cli@10 @angular/core@10

Upgrade of NGRX:
16. ng update @ngrx/store

FINISHED

My angular.json:

{
    "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json",
    "version": 1,
    "defaultProject": "app",
    "newProjectRoot": "projects",
    "projects": {
        "app": {
            "root": "",
            "sourceRoot": "src",
            "projectType": "application",
            "prefix": "app",
            "schematics": {},
            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": {
                        "allowedCommonJsDependencies": [
                            "chart.js",
                            "firebase/app",
                            "@firebase/performance",
                            "crypto-js",
                            "@firebase/firestore",
                            "@firebase/auth",
                            "@firebase/database"
                        ],
                        "aot": true,
                        "outputPath": "www",
                        "index": "src/index.html",
                        "main": "src/main.ts",
                        "polyfills": "src/polyfills.ts",
                        "tsConfig": "src/tsconfig.app.json",
                        "assets": [{
                                "glob": "**/*",
                                "input": "src/assets",
                                "output": "assets"
                            },
                            {
                                "glob": "**/*.svg",
                                "input": "node_modules/ionicons/dist/ionicons/svg",
                                "output": "./svg"
                            },
                            "src/manifest.json"
                        ],
                        "styles": [{
                                "input": "src/theme/variables.scss"
                            },
                            {
                                "input": "src/global.scss"
                            },
                            {
                                "input": "src/app/app.scss"
                            }
                        ],
                        "scripts": []
                    },
                    "configurations": {
                        "production": {
                            "fileReplacements": [{
                                "replace": "src/environments/environment.ts",
                                "with": "src/environments/environment.prod.ts"
                            }],
                            "optimization": true,
                            "outputHashing": "all",
                            "sourceMap": false,
                            "extractCss": true,
                            "namedChunks": false,
                            "aot": true,
                            "extractLicenses": true,
                            "vendorChunk": false,
                            "buildOptimizer": true,
                            "budgets": [{
                                    "type": "initial",
                                    "maximumWarning": "2mb",
                                    "maximumError": "5mb"
                                },
                                {
                                    "type": "anyComponentStyle",
                                    "maximumWarning": "6kb"
                                }
                            ],
                            "serviceWorker": true,
                            "ngswConfigPath": "src/ngsw-config.json"
                        },
                        "uat": {
                            "optimization": true,
                            "outputHashing": "all",
                            "sourceMap": false,
                            "extractCss": true,
                            "namedChunks": false,
                            "aot": true,
                            "extractLicenses": true,
                            "vendorChunk": false,
                            "buildOptimizer": true,
                            "budgets": [{
                                    "type": "initial",
                                    "maximumWarning": "2mb",
                                    "maximumError": "5mb"
                                },
                                {
                                    "type": "anyComponentStyle",
                                    "maximumWarning": "6kb"
                                }
                            ],
                            "serviceWorker": false,
                            "ngswConfigPath": "src/ngsw-config.json"
                        },
                        "ci": {
                            "budgets": [{
                                "type": "anyComponentStyle",
                                "maximumWarning": "6kb"
                            }],
                            "progress": false
                        }
                    }
                },
                "serve": {
                    "builder": "@angular-devkit/build-angular:dev-server",
                    "options": {
                        "browserTarget": "app:build"
                    },
                    "configurations": {
                        "production": {
                            "browserTarget": "app:build:production"
                        },
                        "ci": {
                            "progress": false
                        }
                    }
                },
                "extract-i18n": {
                    "builder": "@angular-devkit/build-angular:extract-i18n",
                    "options": {
                        "browserTarget": "app:build"
                    }
                },
                "test": {
                    "builder": "@angular-devkit/build-angular:karma",
                    "options": {
                        "main": "src/test.ts",
                        "polyfills": "src/polyfills.ts",
                        "tsConfig": "src/tsconfig.spec.json",
                        "karmaConfig": "src/karma.conf.js",
                        "styles": [],
                        "scripts": [],
                        "assets": [{
                                "glob": "favicon.ico",
                                "input": "src/",
                                "output": "/"
                            },
                            {
                                "glob": "**/*",
                                "input": "src/assets",
                                "output": "/assets"
                            },
                            "src/manifest.json"
                        ]
                    },
                    "configurations": {
                        "ci": {
                            "progress": false,
                            "watch": false
                        }
                    }
                },
                "lint": {
                    "builder": "@angular-devkit/build-angular:tslint",
                    "options": {
                        "tsConfig": [
                            "src/tsconfig.app.json",
                            "src/tsconfig.spec.json"
                        ],
                        "exclude": [
                            "**/node_modules/**"
                        ]
                    }
                },
                "ionic-cordova-build": {
                    "builder": "@ionic/angular-toolkit:cordova-build",
                    "options": {
                        "browserTarget": "app:build"
                    },
                    "configurations": {
                        "production": {
                            "browserTarget": "app:build:production"
                        }
                    }
                },
                "ionic-cordova-serve": {
                    "builder": "@ionic/angular-toolkit:cordova-serve",
                    "options": {
                        "cordovaBuildTarget": "app:ionic-cordova-build",
                        "devServerTarget": "app:serve"
                    },
                    "configurations": {
                        "production": {
                            "cordovaBuildTarget": "app:ionic-cordova-build:production",
                            "devServerTarget": "app:serve:production"
                        }
                    }
                }
            }
        },
        "app-e2e": {
            "root": "e2e/",
            "projectType": "application",
            "architect": {
                "e2e": {
                    "builder": "@angular-devkit/build-angular:protractor",
                    "options": {
                        "protractorConfig": "e2e/protractor.conf.js",
                        "devServerTarget": "app:serve"
                    },
                    "configurations": {
                        "production": {
                            "devServerTarget": "app:serve:production"
                        },
                        "ci": {
                            "devServerTarget": "app:serve:ci"
                        }
                    }
                },
                "lint": {
                    "builder": "@angular-devkit/build-angular:tslint",
                    "options": {
                        "tsConfig": "e2e/tsconfig.e2e.json",
                        "exclude": [
                            "**/node_modules/**"
                        ]
                    }
                }
            }
        }
    },
    "cli": {
        "defaultCollection": "@ionic/angular-toolkit"
    },
    "schematics": {
        "@ionic/angular-toolkit:component": {
            "styleext": "scss"
        },
        "@ionic/angular-toolkit:page": {
            "styleext": "scss"
        }
    }
}

Btw, in some point in time the ng cli says I need to remove some angular-devkit subpackages (core/schematics), and I changed the schema to "$schema": "./node_modules/@angular/cli/lib/config/schema.json",, but in vain…

Hi. Bumping. Anyone any suggestions? Thx!!!

Any chance of a peek at package.json?

Hi, sure thing. Thx. Tom

{
  "name": "xxxx",
  "version": "0.65.0",
  "author": "xxxx",
  "homepage": "http://zzzzzz",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^10.0.11",
    "@angular/core": "^10.0.11",
    "@angular/fire": "^5.2.1",
    "@angular/forms": "^10.0.11",
    "@angular/platform-browser": "^10.0.11",
    "@angular/platform-browser-dynamic": "^10.0.11",
    "@angular/router": "^10.0.11",
    "@angular/service-worker": "^10.0.11",
    "@ionic-native/android-full-screen": "^5.10.0",
    "@ionic-native/badge": "^5.10.0",
    "@ionic-native/barcode-scanner": "^5.10.0",
    "@ionic-native/camera": "^5.10.0",
    "@ionic-native/clipboard": "^5.10.0",
    "@ionic-native/core": "^5.0.0",
    "@ionic-native/device": "^5.10.0",
    "@ionic-native/device-accounts": "^5.10.0",
    "@ionic-native/device-motion": "^5.10.0",
    "@ionic-native/file": "^5.10.0",
    "@ionic-native/geolocation": "^5.11.0",
    "@ionic-native/google-plus": "^5.12.0",
    "@ionic-native/keyboard": "^5.11.0",
    "@ionic-native/network": "^5.11.0",
    "@ionic-native/pedometer": "^5.10.0",
    "@ionic-native/qr-scanner": "^5.10.0",
    "@ionic-native/screenshot": "^5.10.0",
    "@ionic-native/sim": "^5.10.0",
    "@ionic-native/sms": "^5.10.0",
    "@ionic-native/sms-retriever": "^5.10.0",
    "@ionic-native/social-sharing": "^5.12.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/sqlite": "^5.10.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic-native/uid": "^5.10.0",
    "@ionic-native/unique-device-id": "^5.10.0",
    "@ionic-native/vibration": "^5.10.0",
    "@ionic/angular": "^5.3.1",
    "@ionic/storage": "^2.2.0",
    "@ngrx/effects": "^10.0.0",
    "@ngrx/entity": "^10.0.0",
    "@ngrx/router-store": "^10.0.0",
    "@ngrx/store": "^10.0.0",
    "@ngrx/store-devtools": "^10.0.0",
    "@ngx-translate/core": "^11.0.1",
    "@ngx-translate/http-loader": "^4.0.0",
    "chart.js": "^2.8.0",
    "com.darktalker.cordova.screenshot": "^0.1.6",
    "cordova-android": "8.0.0",
    "cordova-clipboard": "^1.3.0",
    "cordova-device-accounts-v2": "^2.0.8",
    "cordova-plugin-badge": "^0.8.8",
    "cordova-plugin-browsertab": "^0.2.0",
    "cordova-plugin-buildinfo": "^2.0.3",
    "cordova-plugin-compat": "^1.2.0",
    "cordova-plugin-customurlscheme": "4.4.0",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-device-motion": "^2.0.1",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-fullscreen": "^1.2.0",
    "cordova-plugin-geolocation": "^4.0.2",
    "cordova-plugin-googleplus": "^8.0.0",
    "cordova-plugin-inappbrowser": "^3.1.0",
    "cordova-plugin-ionic": "^5.4.0",
    "cordova-plugin-ionic-keyboard": "^2.1.3",
    "cordova-plugin-ionic-webview": "^4.1.1",
    "cordova-plugin-network-information": "^2.0.2",
    "cordova-plugin-pedometer": "^0.4.1",
    "cordova-plugin-sim": "^1.3.3",
    "cordova-plugin-sms-retriever-manager": "0.0.2",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-uid": "^1.3.0",
    "cordova-plugin-uniquedeviceid": "^1.3.2",
    "cordova-plugin-vibration": "^3.1.1",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-plugin-x-socialsharing": "^5.4.7",
    "cordova-sqlite-storage": "^3.2.1",
    "cordova-universal-links-plugin-fix": "1.2.1",
    "core-js": "^2.5.4",
    "crypto-js": "^3.1.9-1",
    "es6-promise-plugin": "^4.2.2",
    "firebase": "^7.19.0",
    "ngrx-store-freeze": "^0.2.4",
    "phonegap-nfc": "^1.0.3",
    "phonegap-plugin-barcodescanner": "^8.1.0",
    "rxjs": "~6.6.2",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/architect": "^0.1000.7",
    "@angular-devkit/build-angular": "~0.1000.7",
    "@angular/cli": "~10.0.7",
    "@angular/compiler": "~10.0.11",
    "@angular/compiler-cli": "~10.0.11",
    "@angular/language-service": "~10.0.11",
    "@ionic/angular-toolkit": "^2.3.2",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.0",
    "first-input-delay": "^0.1.3",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~3.3.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.9.7"
  },
  "description": "Scoor",
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-ionic": {
        "APP_ID": "xxxxxxx",
        "CHANNEL_NAME": "Production",
        "UPDATE_METHOD": "background",
        "MAX_STORE": "2",
        "MIN_BACKGROUND_DURATION": "30",
        "UPDATE_API": "https://api.ionicjs.com"
      },
      "cordova-plugin-fullscreen": {},
      "cordova-plugin-badge": {},
      "phonegap-plugin-barcodescanner": {
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      },
      "cordova-clipboard": {},
      "cordova-device-accounts-v2": {},
      "cordova-plugin-device-motion": {},
      "cordova-plugin-file": {},
      "cordova-plugin-geolocation": {},
      "phonegap-nfc": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-pedometer": {},
      "com.darktalker.cordova.screenshot": {},
      "cordova-plugin-sim": {},
      "cordova-plugin-vibration": {},
      "cordova-plugin-uniquedeviceid": {},
      "cordova-plugin-dreamover-uid": {},
      "cordova-plugin-sms-retriever-manager": {
        "PLAY_SERVICES_VERSION": "15.0.1"
      },
      "cordova-sqlite-storage": {},
      "cordova-plugin-x-socialsharing": {
        "ANDROID_SUPPORT_V4_VERSION": "24.1.1+"
      },
      "cordova-plugin-buildinfo": {},
      "cordova-universal-links-plugin": {},
      "cordova-plugin-browsertab": {},
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-customurlscheme": {
        "URL_SCHEME": "com.firebase.cordova",
        "ANDROID_SCHEME": " ",
        "ANDROID_HOST": " ",
        "ANDROID_PATHPREFIX": "/"
      },
      "cordova-plugin-googleplus": {
        "PLAY_SERVICES_VERSION": "11.8.0"
      }
    },
    "platforms": [
      "android"
    ]
  }
}

and main.ts which only differs from a newly baked project in having to include the angular compiler

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

import '@angular/compiler';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));

Thanks. Apologies if you’ve seen it before, but angular #35788 tingles my spidey-sense a bit here.

1 Like

Thank you very much. I overlooked that one. Sorry! Should have been easy to find.
Testing now. Many options given, but it seems mostly related to outdated dependencies. Will post here if I found the solution.

Running npm update, removing node_modules, deleting package-lock.json and rerunning npm i seemed to have done the trick. And now I assume it is running AOT.

Bundle size has almost doubled this way from Angular7/Ionic 4. Not sure if that makes me happy. Anyway, performance blast in return, I assume.

1 Like

I’m super-excited about the new localization stuff in 10.1, so I finally got to start playing around with 10 yesterday. By any chance, are you seeing warnings about CommonJS modules at build time? I’m thinking that might be a potential cause for your bundle bloat.

1 Like

Hi, yes, configured angular.json to ignore them until I time to replace if at all

Will stop at angular 8 as bundle size is bit of issue. I release to low bandwidth userbase