Angular 8'ng serve'在找不到'AppModule'的NgModule元数据中产生错误

时间:2019-07-16 20:06:12

标签: angular typescript angular8

我最近尝试通过遵循角度更新指南升级到Angular 8。更新所有软件包和所有对等依赖项之后,当我运行“ ng serve”时,出现以下错误:

ERROR in No NgModule metadata found for 'AppModule'.

我搜寻了互联网,但没有发现任何有用的信息。我尝试了所有发现的建议,但都没有帮助。任何帮助将不胜感激。这是我的设置:

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 8.1.1
Node: 11.12.0
OS: darwin x64
Angular: 8.1.1
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.801.1
@angular-devkit/build-angular     0.801.1
@angular-devkit/build-optimizer   0.801.1
@angular-devkit/build-webpack     0.801.1
@angular-devkit/core              8.1.1
@angular-devkit/schematics        8.1.1
@angular/cdk                      8.1.0
@angular/material                 8.1.0
@ngtools/webpack                  8.1.1
@schematics/angular               8.1.1
@schematics/update                0.801.1
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.35.3

package.json:

"dependencies": {
    "@amcharts/amcharts3-angular": "^2.2.1",
    "@angular-devkit/build-angular": "~0.801.1",
    "@angular/animations": "^8.1.1",
    "@angular/cdk": "^8.1.0",
    "@angular/common": "^8.1.1",
    "@angular/compiler": "^8.1.1",
    "@angular/compiler-cli": "^8.1.1",
    "@angular/core": "^8.1.1",
    "@angular/forms": "^8.1.1",
    "@angular/language-service": "^8.1.1",
    "@angular/material": "^8.1.0",
    "@angular/platform-browser": "^8.1.1",
    "@angular/platform-browser-dynamic": "^8.1.1",
    "@angular/platform-server": "^8.1.1",
    "@angular/router": "^8.1.1",
    "@has/amcharts-has": "^3.20.10",
    "@ng-bootstrap/ng-bootstrap": "^5.0.0",
    "@ngrx/core": "^1.2.0",
    "@ngrx/effects": "^8.1.0",
    "@ngrx/router-store": "^8.1.0",
    "@ngrx/store": "^8.1.0",
    "@ngrx/store-devtools": "^8.1.0",
    "@ngx-translate/core": "^9.1.1",
    "@ngx-translate/http-loader": "^2.0.1",
    "@stomp/stompjs": "^4.0.8",
    "angular2-text-mask": "^9.0.0",
    "animate.css": "^3.7.0",
    "base64-js": "^1.2.1",
    "bootstrap": "4.0.0",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.6.5",
    "cors": "^2.8.5",
    "element-resize-detector": "^1.1.15",
    "font-awesome": "4.7.0",
    "handsontable": "^0.36.0",
    "intl": "1.2.4",
    "jquery": "3.2.1",
    "jquery-mousewheel": "3.1.13",
    "jquery-slimscroll": "1.3.8",
    "lodash": "^4.17.11",
    "moment": "^2.24.0",
    "ng2-completer": "^1.3.1",
    "ng2-handsontable": "^2.1.0-rc.3",
    "ngx-cookie-service": "^1.0.10",
    "ngx-device-detector": "^1.3.5",
    "ngx-logger": "^3.3.11",
    "ngx-smart-modal": "^7.1.1",
    "ngx-uploader": "^4.2.2",
    "normalize.css": "^6.0.0",
    "persistent-websocket": "^1.0.2",
    "popper.js": "^1.14.7",
    "roboto-fontface": "^0.9.0",
    "rxjs": "^6.5.2",
    "rxjs-tslint": "^0.1.7",
    "scroll-into-view-if-needed": "1.5.1",
    "tether": "^1.4.5",
    "text-encoding": "^0.6.4",
    "tslib": "^1.9.0",
    "web-animations-js": "^2.3.2",
    "webpack": "^4.35.3",
    "webpack-cli": "^3.2.3",
    "webpack-dev-server": "^3.2.1",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.13.5",
    "@angular/cli": "^8.1.1",
    "@types/base64-js": "^1.2.5",
    "@types/jasmine": "^2.8.16",
    "@types/jquery": "^2.0.53",
    "@types/jquery.slimscroll": "^1.3.30",
    "@types/lodash": "^4.14.122",
    "@types/node": "^6.14.4",
    "@types/text-encoding": "0.0.33",
    "codelyzer": "^5.0.1",
    "jasmine-core": "^3.3.0",
    "jasmine-spec-reporter": "^4.2.1",
    "karma": "^2.0.5",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "^1.0.1",
    "karma-coverage-istanbul-reporter": "^1.4.1",
    "karma-jasmine": "^1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "npm-run-all": "^4.1.5",
    "protractor": "^5.4.2",
    "rxjs-tslint-rules": "^4.24.3",
    "standard-changelog": "^1.0.13",
    "stylelint": "^9.10.1",
    "ts-node": "^5.0.0",
    "tslint": "^5.13.1",
    "tslint-eslint-rules": "^5.4.0",
    "typescript": "^3.4.5",
    "typogr": "^0.6.8",
    "underscore": "1.8.3"
  }

app.module.ts:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { AppTranslationModule } from './app.translation.module';
import { TextMaskModule } from 'angular2-text-mask';
import { NgxSmartModalModule, NgxSmartModalService } from 'ngx-smart-modal';
import { DeviceDetectorModule } from 'ngx-device-detector';
import { AuthModule } from './auth/auth.module';

/*
 * Platform and Environment providers/directives/pipes
 */
// import { routing } from './app.routing';

// App is our top level component
import { App } from './app.component';
import { AppState, InternalStateType } from './app.service';
import { GlobalState } from './global.state';
import { NgaModule } from './theme/nga.module';
import { PagesModule } from './pages/pages.module';
import { HttpClientModule } from '@angular/common/http';
import { LoggerModule, NgxLoggerLevel } from 'ngx-logger';
import { AmChartsModule } from '@amcharts/amcharts3-angular';
import { environment } from '../environments/environment';
import { RestServiceEndpointService } from './rest-service-endpoint.service';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HomeComponent } from './home/home.component';
import { MainHeaderComponent } from './main-header/main-header.component';
import { BrandingService } from './shared/service/branding.service';
import { AutofocusDirective } from './autofocus.directive';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { CookieService } from 'ngx-cookie-service';
import { MainFooterComponent } from './main-footer/main-footer.component';
import { NavigationService } from './shared/service/navigation.service';
import { AppRoutingModule } from './app.routing';

// Application wide providers
const APP_PROVIDERS = [
  AppState,
  GlobalState,
  RestServiceEndpointService,
  BrandingService,
  CookieService,
  NgxSmartModalService,
  NavigationService
];

export type StoreType = {
  state: InternalStateType,
  restoreInputValues: () => void,
  disposeOldHosts: () => void
};

/**
 * `AppModule` is the main entry point into Angular2's bootstraping process
 */
@NgModule({
  bootstrap: [App],
  declarations: [
    App,
    MainHeaderComponent,
    HomeComponent,
    AutofocusDirective,
    PageNotFoundComponent,
    MainFooterComponent
  ],
  imports: [ // import Angular's modules
    AmChartsModule,
    BrowserModule,
    BrowserAnimationsModule,
    HttpClientModule,
    RouterModule,
    FormsModule,
    ReactiveFormsModule,
    LoggerModule.forRoot({level: (environment.loggingLevel === NgxLoggerLevel.DEBUG ? NgxLoggerLevel.DEBUG :
                                            (environment.loggingLevel === NgxLoggerLevel.INFO ? NgxLoggerLevel.INFO :
                                              (environment.loggingLevel === NgxLoggerLevel.WARN ? NgxLoggerLevel.WARN :
                                                (environment.loggingLevel === NgxLoggerLevel.ERROR ?
                                                  NgxLoggerLevel.ERROR : NgxLoggerLevel.OFF)
                                              )
                                            )
                                          ), serverLogLevel : NgxLoggerLevel.OFF}),
    NgaModule.forRoot(),
    NgxSmartModalModule.forRoot(),
    DeviceDetectorModule.forRoot(),
    PagesModule,
    AppTranslationModule,
    TextMaskModule,
    AuthModule,
    AppRoutingModule
  ],
  providers: [ // expose our Services and Providers into Angular's dependency injection
    APP_PROVIDERS
  ]
})

export class AppModule {
}

tsconfig.app.json:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": ".",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "importHelpers": true,
    "module": "esnext",
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "allowJs": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ],
    "plugins": [
      { "name": "tslint-language-service"}
    ],
    "downlevelIteration": true
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "preserveWhitespaces": false,
    "strictMetadataEmit": true
  }
}

main.ts:

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

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);

让我知道我是否遗漏了任何信息。在此先感谢!

0 个答案:

没有答案