角AOT编译器 - 类型错误:this.compiler.analyzeModulesAsync不是一个函数

角AOT编译器 - 类型错误:this.compiler.analyzeModulesAsync不是一个函数

问题描述:

我试图跟随时间的提前(AOT)编译器指令这里:角AOT编译器 - 类型错误:this.compiler.analyzeModulesAsync不是一个函数

https://angular.io/guide/aot-compiler

的项目我的工作使用快速启动种子已经研制成功,如下所述:

https://angular.io/guide/setup

该项目一直工作正常不使用AOT编译器,但是当我试图按照指示获取AOT编译器的工作,我得到以下错误(这是Windows 8):

C:\Users\zzzzz\Desktop\quickstart>"node_modules/.bin/ngc" -p ./src 
TypeError: this.compiler.analyzeModulesAsync is not a function 
    at CodeGenerator.codegen (C:\Users\zzzzz\Desktop\quickstart\node_modules\@angular\compiler-cli\src\codegen.js:32:14) 
    at codegen (C:\Users\zzzzz\Desktop\quickstart\node_modules\@angular\compiler-cli\src\main.js:13:81) 
    at Object.main (C:\Users\zzzzz\Desktop\quickstart\node_modules\@angular\tsc-wrapped\src\main.js:98:16) 
    at main (C:\Users\zzzzz\Desktop\quickstart\node_modules\@angular\compiler-cli\src\main.js:19:16) 
    at Object.<anonymous> (C:\Users\zzzzz\Desktop\quickstart\node_modules\@angular\compiler-cli\src\main.js:35:5) 
    at Module._compile (module.js:570:32) 
    at Object.Module._extensions..js (module.js:579:10) 
    at Module.load (module.js:487:32) 
    at tryModuleLoad (module.js:446:12) 
    at Function.Module._load (module.js:438:3) 
Compilation failed 

我的package.json文件看起来像这样:

{ 
    "name": "angular-quickstart", 
    "version": "1.0.0", 
    "description": "QuickStart package.json from the documentation, supplemented with testing support", 
    "scripts": { 
    "build": "tsc -p src/", 
    "build:watch": "tsc -p src/ -w", 
    "build:e2e": "tsc -p e2e/", 
    "serve": "lite-server -c=bs-config.json", 
    "serve:e2e": "lite-server -c=bs-config.e2e.json", 
    "prestart": "npm run build", 
    "start": "concurrently \"npm run build:watch\" \"npm run serve\"", 
    "pree2e": "npm run build:e2e", 
    "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first", 
    "preprotractor": "webdriver-manager update", 
    "protractor": "protractor protractor.config.js", 
    "pretest": "npm run build", 
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"", 
    "pretest:once": "npm run build", 
    "test:once": "karma start karma.conf.js --single-run", 
    "lint": "tslint ./src/**/*.ts -t verbose" 
    }, 
    "keywords": [], 
    "author": "", 
    "license": "MIT", 
    "dependencies": { 
    "@angular/common": "~4.0.0", 
    "@angular/compiler": "~4.0.0", 
    "@angular/compiler-cli": "^4.2.2", 
    "@angular/core": "~4.0.0", 
    "@angular/forms": "~4.0.0", 
    "@angular/http": "~4.0.0", 
    "@angular/platform-browser": "~4.0.0", 
    "@angular/platform-browser-dynamic": "~4.0.0", 
    "@angular/platform-server": "^4.2.2", 
    "@angular/router": "~4.0.0", 
    "@ngrx/core": "~1.2.0", 
    "@ngrx/store": "~2.2.2", 
    "angular-in-memory-web-api": "~0.3.0", 
    "core-js": "^2.4.1", 
    "rxjs": "5.0.1", 
    "systemjs": "0.19.40", 
    "zone.js": "^0.8.4" 
    }, 
    "devDependencies": { 
    "@types/jasmine": "2.5.36", 
    "@types/node": "^6.0.46", 
    "canonical-path": "0.0.2", 
    "concurrently": "^3.2.0", 
    "jasmine-core": "~2.4.1", 
    "karma": "^1.3.0", 
    "karma-chrome-launcher": "^2.0.0", 
    "karma-cli": "^1.0.1", 
    "karma-jasmine": "^1.0.2", 
    "karma-jasmine-html-reporter": "^0.2.2", 
    "lite-server": "^2.2.2", 
    "lodash": "^4.16.4", 
    "protractor": "~4.0.14", 
    "rimraf": "^2.5.4", 
    "tslint": "^3.15.1", 
    "typescript": "~2.1.0" 
    }, 
    "repository": {} 
} 

当我检查@角/编译我安装的是什么版本,我得到4.2.2,这似乎是最新版本:

C:\Users\zzzzz\Desktop\quickstart>npm view @angular/compiler version 
4.2.2 

查看源在Github上,我看到有一个福nction称为analyzeModulesAsync在角/包/编译/ src目录/ AOT/compiler.ts:

https://github.com/angular/angular/blob/master/packages/compiler/src/aot/compiler.ts

然而,当我为做我的node_modules文件夹的grep analyzeModulesAsync,我只看到电话到那个功能。我没有看到它的定义。事实上,compiler.d.ts中的类定义似乎与Github上的compiler.ts文件有几处不同。

我试过通过删除整个node_modules文件夹并重新运行npm install来“重新安装”,并且错误消息是相同的。

我的确在这里看到了一个类似的问题:Angular AOT failing at compilation (something with angular/compiler-cli),但是我对npm版本知之甚少,不知道可能是什么原因,或者如何解决它。

任何关于我是否在某处弄糟了某些指示,或者有更深层次的工作的想法?

SOLUTION

的问题是与@角/编译器,CLI的版本不匹配,并在@角的package.json /平台的服务器。一旦我将它们更改为“〜4.0.0”以匹配剩余的角度模块,删除了node_modules文件夹并重新运行npm install,编译器就工作了。

我的工作理论是,因为我在两周前克隆了quickstart,并且昨天从教程中运行了此命令:npm install @angular/compiler-cli @angular/platform-server --save,这就是导致版本不匹配的原因。

+1

为什么要使用不同版本的'编译器(“〜4.0.0”)'和'编译器CL(“^ 4.2.2” )i'? – yurzui

+1

当我尝试修复从教程中运行此命令时遇到的问题时,可能发生* npm install @ angular/compiler-cli @ angular/platform-server --save。无论如何,我在我的package.json中使所有版本保持一致,删除了node_modules,重新运行npm install,现在看起来编译器工作正常! – Rolandus

@Rolandus:你砸了它,我刚刚克隆了quickstart,然后今天添加了aot包,这些包都是最新的。将版本号匹配到4.0。0工作,但只有一次我用波浪而不是插入符^