我正在尝试将AOT集成到我的角度项目中,所以我按照Angular.io执行此操作,在运行以下命令后,AOT文件夹和文件成功生成且没有错误:
"node_modules/.bin/ngc" -p tsconfig-aot.json
但是当我在浏览器中运行应用程序时,我在控制台中收到以下错误:
Fetch error: 404 Not Found
Instantiating
http://localhost:55019/aot/wwwroot/typescript/modules/app.module.ngfactory
Loading http://localhost:55019/typescript/main.js
Loading app
at system.src.js:1500
at ZoneDelegate.invoke (zone.js:391)
at Zone.run (zone.js:141)
at zone.js:817
at ZoneDelegate.invokeTask (zone.js:424)
at Zone.runTask (zone.js:191)
at drainMicroTaskQueue (zone.js:584)
at <anonymous>
我确信我的AOT文件夹中有app.module.ngfactory。
这是我的package.json文件
{
"name": "angular-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/angular/angular.io/blob/master/LICENSE"
}
],
"dependencies": {
"@angular/common": "4.1.3",
"@angular/compiler": "4.1.3",
"@angular/compiler-cli": "4.1.3",
"@angular/core": "4.1.3",
"@angular/forms": "4.1.3",
"@angular/http": "4.1.3",
"@angular/platform-browser": "4.1.3",
"@angular/platform-browser-dynamic": "4.1.3",
"@angular/router": "4.1.3",
"@angular/upgrade": "4.1.3",
"angular-in-memory-web-api": "0.3.2",
"bootstrap": "3.3.7",
"angular2-jwt": "0.2.3",
"core-js": "2.4.1",
"reflect-metadata": "0.1.10",
"rxjs": "5.4.0",
"es6-promise": "4.1.0",
"systemjs": "0.20.12",
"zone.js": "0.8.11",
"ng2-translate": "5.0.0",
"jquery": "3.2.1",
"jquery-migrate": "3.0.0",
"jszip": "3.1.3",
},
"devDependencies": {
"concurrently": "3.4.0",
"lite-server": "2.3.0",
"gulp": "^3.9.1",
"typescript": "2.3.2",
"typings": "2.1.1"
}
}
这里是tsconfig-aot.josn:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true
},
"files": [
"wwwroot/typescript/modules/shared.module.ts",
"wwwroot/typescript/modules/test.module.ts",
"wwwroot/typescript/modules/app.module.ts",
"wwwroot/typescript/main.ts"
],
"angularCompilerOptions": {
"genDir": "./wwwroot/aot",
"skipMetadataEmit" : true
}
}
答案 0 :(得分:0)
看起来您正在使用systemjs,并且它不知道如何加载app.module.ngfactor。这很可能是因为您没有告诉systemjs这是一个javascript文件。
如果没有看到你的systemjs.config.js文件,我认为你可以通过添加&#34; defaultJSExtensions&#34;:true来解决这个问题。 e.g。
System.config({
"defaultJSExtensions": true
});