我试图首次使用AOT编译启动我的Angular5应用程序,并在尝试此操作时出现以下错误。
compiler.js:20242 Uncaught Error: No NgModule metadata found for 'AppModule'.
at NgModuleResolver.resolve (compiler.js:20242)
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:15195)
at JitCompiler._loadModules (compiler.js:34405)
at JitCompiler._compileModuleAndComponents (compiler.js:34366)
at JitCompiler.compileModuleAsync (compiler.js:34260)
at CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:239)
at PlatformRef.bootstrapModule (core.js:5567)
at eval (main.ts:14)
at Object../src/main.ts (main.bundle.js:269)
at __webpack_require__ (inline.bundle.js:55)
这是当我运行以下命令启动应用程序时:
ng serve --aot true
当我在没有--aot true标志的情况下启动应用程序时,应用程序正确启动并正常运行。
由于这是我第一次尝试AOT编辑,我不知道从哪里开始。
这是我的app.module文件:
import { NgModule, ErrorHandler, APP_INITIALIZER } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { LayoutModule } from './layout/layout.module';
import { RoutesModule } from './routes/routes.module';
import { CoreModule } from './core/core.module';
import { PreLoaderService } from './core/preLoader/preLoader.service';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
BrowserAnimationsModule,
CoreModule,
RoutesModule,
LayoutModule
],
providers: [
PreLoaderService
],
bootstrap: [
AppComponent
]
})
export class AppModule { }
我的main.ts文件:
import './polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
import { AppModule } from './app/';
const platform = platformBrowserDynamic();
if (environment.production) {
enableProdMode();
}
platform.bootstrapModule(AppModule);
我的.tsconfig文件
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"mapRoot": "./",
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types"
]
}
}
我的angular-cli.json文件
{
"project": {
"version": "1.0.0-beta.19-3",
"name": "q2c-shell"
},
"apps": [{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.png"
],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
"styles": [
"styles.scss",
"../node_modules/openlayers/css/ol.css",
"../node_modules/loaders.css/loaders.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/bootstrap/js/tab.js",
"../node_modules/bootstrap/js/dropdown.js",
"../node_modules/openlayers/dist/ol.js",
"../node_modules/proj4/dist/proj4.js",
"../node_modules/web-animations-js/web-animations.min.js",
"../node_modules/jsts/dist/jsts.min.js",
"../node_modules/blob-util/dist/blob-util.min.js",
"./assets/js/fontawesome-all.min.js",
"./assets/js/fa-v4-shims.min.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"bvt": "environments/environment.bvt.ts",
"uat": "environments/environment.uat.ts",
"prod": "environments/environment.prod.ts"
}
}],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "scss",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
有人能看出为什么会出现这种错误吗? 感谢