我尝试使用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 {}
答案 0 :(得分:1)
我找到了一个解决方法,我写错了main.ts
platformBrowser().bootstrapModuleFactory(AppModule);
必须
platformBrowser().bootstrapModule(AppModule);
AOT编译器成功运作!