gpt4 book ai didi

Angular AOT 编译器 - TypeError : this. compiler.analyzeModulesAsync 不是函数

转载 作者:太空狗 更新时间:2023-10-29 17:59:08 25 4
gpt4 key购买 nike

我在这里尝试遵循提前 (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

但是,当我对 analyzeModulesAsync 的 node_modules 文件夹执行 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”以匹配其余的 Angular 模块,删除 node_modules 文件夹并重新运行 npm install,编译器就可以工作了。

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

最佳答案

@Rolandus:你搞砸了,我刚才克隆​​了 quickstart,然后今天添加了设置为最新的 aot 包。将版本号与 4.0.0 相匹配但只有一次我使用波浪号 ~ 而不是插入符号 ^

关于Angular AOT 编译器 - TypeError : this. compiler.analyzeModulesAsync 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44571163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com