我試圖跟隨時間的提前(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
,這就是導致版本不匹配的原因。
爲什麼要使用不同版本的'編譯器(「〜4.0.0」)'和'編譯器CL(「^ 4.2.2」 )i'? – yurzui
當我嘗試修復從教程中運行此命令時遇到的問題時,可能發生* npm install @ angular/compiler-cli @ angular/platform-server --save。無論如何,我在我的package.json中使所有版本保持一致,刪除了node_modules,重新運行npm install,現在看起來編譯器工作正常! – Rolandus