4
ng build --configuration=production --base-href /my-app/ --prod

generally this is my way of building my angular 8 app for production. however in my current app it is giving me an error while compiling.

ERROR in Illegal State: referring to a type without a variable {"filePath":"/node_modules/@angular/router/router.d.ts","name":"RouterLink","members":[]}

Quick search suggested to set build-optimizer & aot flags to false. The build process is successful on executing:

ng build --configuration=production --base-href /my-app/ --prod --build-optimizer=false --aot=false

I have two queries:

  1. What is the referring to a type without a variable error issue? I don't mind sharing my code, but unable to understand what part of the code should be shared as i couldn't understand the relevance of the error.

  2. Is it okay to set aot to false? A medium blog suggests

    The performance improvements with AOT are too significant to ignore

My package.json is as follows

{
  "name": "my-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.0",
    "@angular/common": "~8.2.0",
    "@angular/compiler": "~8.2.0",
    "@angular/core": "~8.2.0",
    "@angular/fire": "^5.2.1",
    "@angular/forms": "~8.2.0",
    "@angular/material": "^8.1.4",
    "@angular/platform-browser": "~8.2.0",
    "@angular/platform-browser-dynamic": "~8.2.0",
    "@angular/router": "~8.2.0",
    "ag-grid-angular": "^21.2.1",
    "ag-grid-community": "^21.2.1",
    "ag-grid-enterprise": "^21.2.1",
    "angular-persistence": "^1.0.1",
    "firebase": "^6.5.0",
    "ng-zorro-antd": "^8.2.1",
    "rxjs": "^6.5.2",
    "rxjs-compat": "^6.5.3",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.802.2",
    "@angular/cli": "~8.2.2",
    "@angular/compiler-cli": "~8.2.0",
    "@angular/language-service": "~8.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}
Lakshman Pilaka
  • 1,803
  • 2
  • 24
  • 48
  • 1
    you shouldnt turn off aot for sure, non aot apps could take 20 seconds to open on average mobile phonse. could you please provide more information of exact versions of angular you are using? the workaround for your issue would be turn off `fullTemplateTypeCheck` for your templates. It is also bad (there will be no type checks on template), but at least it won't ruin runtime perfomance – Andrei Sep 12 '19 at 15:10
  • setting `fullTemplateTypeCheck` to `false` has compiled without issues with aot. Thanks for the input. But still struggling to find the actual issue. – Lakshman Pilaka Sep 12 '19 at 15:53
  • 1
    the problem is most likely in usage of `routerLink` directive in a `component `belonging to a `module` that has no `RouterModule` imported into it. – Andrei Sep 12 '19 at 16:10
  • Wil check and revert – Lakshman Pilaka Sep 12 '19 at 16:18
  • Why revert? just add RouterModule to that components module and error will disappear – Andrei Sep 12 '19 at 16:19
  • Revert means will post the answer :) – Lakshman Pilaka Sep 12 '19 at 16:20

0 Answers0