0

我正在尝试将 AOT 集成到我的 Angular 项目中,所以我按照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
 }
}
4

1 回答 1

0

看起来您正在使用 systemjs,但它不知道如何加载 app.module.ngfactor。这可能是因为您没有告诉 systemjs 这是一个 javascript 文件。

在没有看到您的 systemjs.config.js 文件的情况下,我认为您可以通过添加 "defaultJSExtensions": true 来解决这个问题。例如

System.config({

  "defaultJSExtensions": true

});
于 2017-06-13T09:17:08.893 回答