Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 7 : "ng serve --aot" fails the after a file change

Tags:

angular

"ng serve --aot" which succeeds first time, fails after a file change every time with the following error

ERROR in Debug Failure. False expression: Host should not return a redirect source file from `getSourceFile`
i 「wdm」: Failed to compile.

Re-running the command works again.

With respect to contents posted in "https://github.com/angular/angular-cli/issues/11835", I have tried down grading "@angular/compiler-cli": to version '6.1.1'. It did not help.

contents of my package.json are as follows,

{
  "name": "matrix-dashboards",
  "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": "^7.1.4",
    "@angular/cdk": "^7.2.0",
    "@angular/common": "~7.1.0",
    "@angular/compiler": "^7.1.4",
    "@angular/core": "~7.1.0",
    "@angular/forms": "~7.1.0",
    "@angular/material": "^7.2.0",
    "@angular/platform-browser": "~7.1.0",
    "@angular/platform-browser-dynamic": "~7.1.0",
    "@angular/router": "~7.1.0",
    "core-js": "^2.5.4",
    "crypto-js": "^3.1.9-1",
    "font-awesome": "^4.7.0",
    "materialize-css": "^1.0.0",
    "roboto-fontface": "^0.10.0",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.11.0",
    "@angular/cli": "~7.1.2",
    "@angular/compiler-cli": "~7.1.0",
    "@angular/language-service": "~7.1.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.6"
  }
}

Appreciate any help, to help me find a way to get "ng serve --aot" to compile the code properly every time a file is changed. Thanks

like image 735
kathikeyan A Avatar asked Dec 19 '18 17:12

kathikeyan A


People also ask

Does ng serve use AOT?

When you run the ng build (build only) or ng serve (build and serve locally) CLI commands, the type of compilation (JIT or AOT) depends on the value of the aot property in your build configuration specified in angular. json . By default, aot is set to true for new CLI applications.

What is NG build -- AOT?

The ng build command with the --prod meta-flag (ng build --prod) compiles with AOT by default. Why compile with AOT? With AOT, the browser downloads a pre-compiled version of the application. The browser loads executable code so it can render the application immediately, without waiting to compile the app first.

What is AOT and JIT in angular?

JIT downloads the compiler and compiles code exactly before Displaying in the browser. AOT has already complied with the code while building your application, so it doesn't have to compile at runtime. Loading in JIT is slower than the AOT because it needs to compile your application at runtime.


1 Answers

Hope this helps other people with such error.

What I found as a solution what an issue in the official Angular CLI repository. In my case the issue was caused by duplicated typing files used for typescript - check here.

After finding the module that was causing the issue through troubleshooting, I was able to fix it. All thanks to the contributors of the issue.

like image 153
Hristo Enev Avatar answered Sep 16 '22 16:09

Hristo Enev