繁体   English   中英

Angular 4 Aot使用CLI编译

[英]Angular 4 Aot compile with cli

我尝试使用Aot编译来编译我的angular4项目,但显示错误

我的package.json

{
"name": "crm",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
 "@angular/animations": "^4.2.4",
 "@angular/common": "^4.2.4",
 "@angular/compiler": "^4.2.4",
 "@angular/compiler-cli": "^4.2.4",
 "@angular/core": "^4.2.4",
 "@angular/forms": "^4.2.4",
 "@angular/http": "^4.2.4",
 "@angular/platform-browser": "^4.2.4",
 "@angular/platform-browser-dynamic": "^4.2.4",
 "@angular/platform-server": "^4.2.4",
 "@angular/router": "^4.2.4",
 "core-js": "^2.4.1",
 "font-awesome": "^4.7.0",
 "ionicons": "^3.0.0",
 "primeng": "^4.0.3",
 "rxjs": "^5.1.0",
 "typescript": "^2.3.4",
 "zone.js": "^0.8.4"
},
"devDependencies": {
  "@angular/cli": "^1.1.3",
  "@angular/compiler-cli": "^2.4.0",
  "@types/jasmine": "2.5.38",
  "@types/node": "~6.0.60",
  "codelyzer": "~2.0.0",
  "jasmine-core": "~2.5.2",
  "jasmine-spec-reporter": "~3.2.0",
  "karma": "~1.4.1",
  "karma-chrome-launcher": "~2.0.0",
  "karma-cli": "~1.0.1",
  "karma-coverage-istanbul-reporter": "^0.2.0",
  "karma-jasmine": "~1.1.0",
  "karma-jasmine-html-reporter": "^0.2.2",
  "protractor": "~5.1.0",
  "ts-node": "~2.0.0",
  "tslint": "~4.4.2",
  "typescript": "^2.3.4"
 }
}

我的main.ts文件

 import { platformBrowser }    from '@angular/platform-browser';
 import { enableProdMode } from '@angular/core';
 import { AppModule } from './app/app.module';
 import { environment } from './environments/environment';

  if (environment.production) {
     enableProdMode();
  }
  platformBrowser().bootstrapModuleFactory(AppModule);

我使用此命令进行编译:

ng build -aot

然后显示错误

ERROR in D:/project_name/src/main.ts (9,42): Argument of type 'typeof AppModule' is not assignable to parameter of type 'NgModuleFactory<{}>'.
Property 'moduleType' is missing in type 'typeof AppModule'.

Jit-编译工作成功,但是Aot编译显示错误,我找不到任何资源来解决此问题,请帮助解决该问题

我的AppModule

import { BrowserModule } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { ButtonModule } from 'primeng/primeng';
import { CheckboxModule } from 'primeng/primeng';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login/login.component';
import {AppRoutingModule} from './app-routing.module';
. . . . . .
import { GlobalDataService } from './services/global-data.service';


@NgModule({
  declarations: [
    AppComponent,
    LoginComponent
  ],
  imports: [
    BrowserModule,
    NoopAnimationsModule,
    FormsModule,
    HttpModule,
    ButtonModule,
    CheckboxModule,
    . . . . . .
    AppRoutingModule
  ],
  providers: [GlobalDataService, AuthGuard],
  bootstrap: [AppComponent]
})
export class AppModule {}

我找到解决方法,我写错了main.ts

platformBrowser().bootstrapModuleFactory(AppModule);

一定是

platformBrowser().bootstrapModule(AppModule);

AOT编译器成功工作!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM