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

Viewed 4070

"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

6 Answers

I was having this same exact problem. After wrestling with it for awhile I deleted my node_modules and package-lock.json files then I ran 'npm install'.... that fixed it!! Good luck.

I had the same error using TurfJS with the following package.json:

"devDependencies": {
  ...
  "@turf/helpers": "^6.1.4",
  "@turf/turf": "^5.1.6",
  ...
}

Unfortunately is @turf/helpers already a dependency of @turf/turf, but in a different version than ^6.1.4.

Solution:
I removed the extra dependency "@turf/helpers": "^6.1.4" and everything worked again. Therefore: Whatch your dependencies, this could also be a reason for the described error.

To expand on @Hristo Enev's answer, the "paths" typescript option solution worked for me. No need to run any extra scripts to delete files. In my case, I had duplicate "source-map" typings, so I added this to my tsconfig:

"paths": { "source-map": ["node_modules/source-map"] }

For me the error was caused by the following npm dependency:

"@sentry/types": "^5.0.0"

I needed to downgrade my Typescript version in package.json and after npm install it worked.

Related