Angular 7:文件更改后,“ ng serve --aot”失败

时间:2018-12-19 17:18:02

标签: angular

“ ng serve --aot”第一次成功,每次更改文件后失败,并显示以下错误

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

重新运行命令将再次起作用。

对于发布在“ https://github.com/angular/angular-cli/issues/11835”中的内容,我尝试将“ @ angular / compiler-cli”降级为版本“ 6.1.1”。它没有帮助。

package.json的内容如下

{
  "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"
  }
}

感谢任何帮助,以帮助我找到一种方法,使“ ng serve --aot”在每次文件更改时都能正确地编译代码。谢谢

6 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。经过一段时间的努力后,我删除了我的node_modules和package-lock.json文件,然后运行了'npm install'....祝你好运。

答案 1 :(得分:1)

希望这可以帮助其他人解决此类错误。

我发现issue in the official Angular CLI repository是解决方案。就我而言,问题是由用于打字稿的重复打字文件引起的-check here

finding the module that was causing the issue经过故障排除之后,我得以修复它。谢谢这个问题的贡献者。

答案 2 :(得分:1)

在使用带有以下package.json的TurfJS时,我遇到了相同的错误:

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

很遗憾,@turf/helpers已经是@turf/turf的依赖项,但是版本与^6.1.4不同。

解决方案:
我删除了额外的依赖项"@turf/helpers": "^6.1.4",然后一切又恢复了。因此:获取依赖项,这也可能是所描述错误的原因。

答案 3 :(得分:0)

要扩展@Hristo Enev的答案,the "paths" typescript option solution为我工作。无需运行任何其他脚本来删除文件。就我而言,我有重复的“源映射”类型,因此我将其添加到了tsconfig中:

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

答案 4 :(得分:0)

对我来说,错误是由以下npm依赖性引起的:

<li>

答案 5 :(得分:0)

我需要在 package.json 中降级我的 Typescript 版本,并且在 npm install 之后它可以工作了。