我在这里尝试遵循提前(AOT)编译器指令:
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": {}
}
当我检查我安装的@ angular / compiler的版本时,我得到4.2.2,这似乎是最新的版本:
C:\Users\zzzzz\Desktop\quickstart>npm view @angular/compiler version
4.2.2
在Github上查看源代码,我看到在angular / packages / compiler / src / aot / compiler.ts中有一个名为analyzeModulesAsync的函数:
https://github.com/angular/angular/blob/master/packages/compiler/src/aot/compiler.ts
但是,当我在我的node_modules文件夹上为analyzeModulesAsync执行grep时,我只看到对该函数的调用.我没有看到它的定义.事实上,compiler.d.ts中的类定义似乎与Github上的compiler.ts文件有几点不同.
我已经尝试通过删除整个node_modules文件夹并重新运行npm install来“重新安装”,并且错误消息是相同的.
我确实在这里看到了一个类似的问题:Angular AOT failing at compilation (something with angular/compiler-cli),但是我对npm版本控制知之甚少,不知道可能出现什么问题,或者如何修复它.
关于我是否在某处篡改了某些指令,或者有更深层次的工作的任何想法?
解
问题在于package.json中@ angular / compiler-cli和@ angular / platform-server的版本不匹配.一旦我将它们更改为“~4.0.0”以匹配其余的角度模块,删除了node_modules文件夹并重新运行npm install,编译器就可以了.
我的工作理论是,因为我在两周前克隆了快速入门,并运行了这个命令:npm install @ angular / compiler-cli @ angular / platform-server – 昨天从教程中保存,这就是导致版本不匹配的原因.
最佳答案 @Rolandus:你砸了它,我刚刚克隆了快速入门,然后今天添加了一套最新的套餐.匹配版本号到4.0.0工作,但只有一次我使用波浪号〜而不是插入^