web-dev-qa-db-ja.com

Angular 2 prod build error:ERROR in Error:Illegal state:couldn load the summary for directive

プロジェクトでangular 2を使用していますが、ng buildおよびng serveを使用すると、次のエラーが発生しません。これは、製品ビルドを使用している場合にのみ発生しますng build --prod

ERROR in Error: Illegal state:
      Could not load the summary for directive "component name"

以下の依存関係が私のプロジェクトで使用されています。

誰でもこの問題を解決してみてください:

Node  :8.10.0

"dependencies": {
    "@angular-devkit/core": "^0.4.3",
    "@angular/animations": "4.4.6",
    "@angular/common": "4.4.6",
    "@angular/compiler": "4.4.6",
    "@angular/compiler-cli": "4.4.6",
    "@angular/core": "4.4.6",
    "@angular/forms": "4.4.6",
    "@angular/http": "4.4.6",
    "@angular/platform-browser": "4.4.6",
    "@angular/platform-browser-dynamic": "4.4.6",
    "@angular/platform-server": "4.4.6",
    "@angular/router": "4.4.6",
    "@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.28",
    "angular2-google-chart": "2.3.0",
    "angular2-jsonwebtoken": "0.8.1",
    "angular2-jwt": "0.2.3",
    "angular2-toaster": "3.0.1",
    "angular2-uuid": "1.1.1",
    "auth0-lock": "11.7.2",
    "aws-sdk": "2.182.0",
    "chart.js": "2.7.1",
    "core-js": "2.5.3",
    "ng2-charts": "1.6.0",
    "ng2-ckeditor": "1.1.6",
    "ng2-google-place-autocomplete": "1.4.2",
    "ng2-inline-editor": "0.1.1-alpha.20",
    "node-datetime": "1.0.1",
    "primeng": "4.3.0",
    "pubnub": "4.20.0",
    "pubnub-angular2": "1.3.0",
    "rxjs": "5.5.6",
    "TypeScript": "2.6.2",
    "typings": "^2.1.1",
    "zone.js": "0.7.8"
  },
  "devDependencies": {
    "@angular/cli": "1.4.2",
    "@angular/compiler-cli": "4.4.6",
    "@types/jasmine": "2.5.38",
    "@types/node": "6.0.96",
    "codelyzer": "2.0.1",
    "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.3",
    "karma-jasmine": "1.1.1",
    "karma-jasmine-html-reporter": "0.2.2",
    "protractor": "5.1.2",
    "ts-node": "2.0.0",
    "tslint": "4.5.1",
    "TypeScript": "2.6.2"
  }

アプリモジュールサービスの宣言:

import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {HttpModule, RequestOptions, Http} from '@angular/http';
import {provideAuth, AuthHttp, AuthConfig} from 'angular2-jwt';

//ThirdParty Modules
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import {ChartsModule} from 'ng2-charts';
import {InlineEditorModule} from 'ng2-inline-editor';
import {GoogleChart} from './shared/directive/angular2-google-chart.directive';
import {OverlayPanelModule, GrowlModule, ConfirmDialogModule, ConfirmationService, DialogModule} from 'primeng/primeng';
import {ToasterModule, ToasterConfig} from 'angular2-toaster';
import {PubNubAngular} from 'pubnub-angular2';
import {ChartModule} from 'primeng/primeng';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations'
import {CalendarModule} from 'primeng/primeng';
import {AutoCompleteModule} from 'primeng/primeng';
import {GooglePlaceModule} from 'ng2-google-place-autocomplete';
import {DataTableModule, SharedModule, PaginatorModule, InputMaskModule, ChipsModule, MultiSelectModule, PickListModule} from 'primeng/primeng';




//Components
import {AppComponent} from './app.component';
import {RegistrationComponent} from './registration/registration.component';
/*import { MywebsiteHeaderComponent } from './dashboard/mywebsite-header/mywebsite-header.component';*/
import {MyReportsComponent} from './my-reports/my-reports.component';
import {MyWebsitesComponent} from './my-websites/my-websites.component';
import {WelcomeMessageComponent} from './welcome-message/welcome-message.component';
import {ViewProfileComponent} from './view-profile/view-profile.component';
import {MyHomeComponent} from './my-home/my-home.component';
import {PrivacyComponent} from './static/privacy/privacy.component';
import {AboutComponent} from './static/about/about.component';
import {SelectWebsiteTypeComponent} from './select-website-type/select-website-type.component';
import {ManageUsersComponent} from './manage-users/manage-users.component';




//Modules
import {RoutingModule} from './routing/routing.module';
import {VerifyEmailComponent} from './verify-email/verify-email.component';
import {VerifyMailSendComponent} from './verify-mail-send/verify-mail-send.component';
import {HomeComponent} from './home/home.component';
import {AdminConsoleComponent} from './admin/admin-console/admin-console.component';
import {BusinessProfileModule} from './dashboard/business-profile/business-profile.module';
import {BrandingModule} from './dashboard/branding/branding.module';
import {PaymentsModule} from './dashboard/payments/payments.module';
import {StripePaymentModule} from './stripe-payment/stripe-payment.module';
import {TrackingCodeModule} from './dashboard/tracking-code/tracking-code.module';
import {InviteMemberModule} from './dashboard/invite-member/invite-member.module';
import {SiteDesignModule} from './dashboard/site-design/site-design.module';
import {QuickwebsiteModule} from './dashboard/quickwebsite/quickwebsite.module';
import {ManageUsersModule} from "./manage-users/manage-users.module";
import {OrganizationChartModule} from 'primeng/primeng';
//import { PreviewPublishModule } from './dashboard/preview-publish/preview-publish.module';

//Services
import {Auth} from './services/auth';
import {AuthGuard} from './services/auth-guard.service';
import {AdminService} from './admin/admin-console/admin.service';
import {GetUserService} from './services/get-user.service';
import {LoggedinGuard} from './loggedin.guard';
import {MyOrgComponent} from './my-org/my-org.component';
import {FirstuserGuard} from './routing/guards/firstuser.guard';

//Directives



import {RequestActivationComponent} from './admin/request-activation/request-activation.component';
import {DataAvailabilityCheckComponent} from './admin/data-availability-check/data-availability-check.component';
import {ApiRequestSuccessComponent} from './api-request-success/api-request-success.component';
import {KeyPersonInfoCollectionComponent} from './key-person-info-collection/key-person-info-collection.component';
import {ThirdpartyInfoComponent} from './admin/thirdparty-info/thirdparty-info.component';
import {GlobalConstantsComponent} from './admin/global-constants/global-constants.component';
import {GlobalConstantsPopupComponent} from './admin/global-constants-popup/global-constants-popup.component';



@NgModule({
    declarations: [

        AppComponent,
        RegistrationComponent,
        VerifyEmailComponent,
        VerifyMailSendComponent,
        HomeComponent,
        AdminConsoleComponent,
        MyHomeComponent,
        MyReportsComponent,
        WelcomeMessageComponent,
        ViewProfileComponent,
        MyOrgComponent,
        MyWebsitesComponent,
        GoogleChart,
        PrivacyComponent,
        AboutComponent,
        SelectWebsiteTypeComponent,
        RequestActivationComponent,
        DataAvailabilityCheckComponent,
        ApiRequestSuccessComponent,
        KeyPersonInfoCollectionComponent,
        ThirdpartyInfoComponent,
        GlobalConstantsComponent,
        GlobalConstantsPopupComponent,

    ],
    imports: [
        BrowserModule,
        FormsModule,
        ReactiveFormsModule,
        HttpModule,
        RoutingModule,
        NgbModule,
        BusinessProfileModule,
        BrandingModule,
        PaymentsModule,
        StripePaymentModule,
        TrackingCodeModule,
        InviteMemberModule,
        SiteDesignModule,
        ChartsModule,
        InlineEditorModule,
        OverlayPanelModule,
        ToasterModule,
        GrowlModule,
        ChartModule,
        BrowserAnimationsModule,
        CalendarModule,
        ConfirmDialogModule,
        AutoCompleteModule,
        QuickwebsiteModule,
        DialogModule,
        GooglePlaceModule,
        DataTableModule,
        SharedModule,
        PaginatorModule,
        InputMaskModule,
        ChipsModule,
        OrganizationChartModule,
        ManageUsersModule,
        MultiSelectModule,
        PickListModule

    ],
    entryComponents: [ HomeComponent, RegistrationComponent, WelcomeMessageComponent, SelectWebsiteTypeComponent, ManageUsersComponent, ApiRequestSuccessComponent, KeyPersonInfoCollectionComponent, GlobalConstantsPopupComponent],
    providers: [
        AdminService,
        Auth,
        AuthGuard,
        GetUserService,
        LoggedinGuard,
        FirstuserGuard,
        PubNubAngular,
    ],
    bootstrap: [AppComponent]
})
export class AppModule {}

Globalconstantpopupファイルの宣言とインポート:

import { Component, OnInit, NgModule, Input } from '@angular/core';
import { NgbModal, NgbActiveModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
import { GlobalConstantsService } from '../global-constants/global-constants.service';
import { GlobalConstantsComponent } from '../global-constants/global-constants.component';

import { InlineEditorModule } from 'ng2-inline-editor';
import { DataTableModule, SharedModule, LazyLoadEvent, PickListModule } from 'primeng/primeng';

@Component({
  selector: 'app-global-constants-popup',
  templateUrl: './global-constants-popup.component.html',
  styleUrls: ['./global-constants-popup.component.css'],
  providers: [GlobalConstantsService],
})
@NgModule({
  imports: [
    InlineEditorModule,

  ]
})
export class GlobalConstantsPopupComponent implements OnInit {

//codes here
}
3
user3541485

問題は、コンポーネントに@NgModuleアノテーションがあるためです。これはサポートされていません(示されているように here

コンポーネントからこれらの行を削除してみてください

@NgModule({
  imports: [
    InlineEditorModule,

 ]
})

代わりにInlineEditorModuleからAppModuleをインポートします

Ithinkこれがdevモードで機能する理由は--prodフラグを使用してビルドする場合ではなく、プロダクションがいくつかのコードの最適化を行うためです(angular.jsonbuildOptimizerパラメータ)。これにより、Componentアノテーションが削除される可能性があります。

1
David

@関数は、@Component@NgModuleなどのデコレータです。これらのデコレータはクラスデコレータです。 NgModuleはngModuleを「定義」するため、クラス宣言の前に@NgModuleを配置して、ngModuleとして定義しました。 @Componentコンポーネントを「定義」します。

GlobalConstantsPopupComponentクラスは両方として「定義済み」であり、angularは満足できません。

@NgModuleGlobalConstantsPopupComponentクラスの下に移動し、その下にGlobalConstantsPopupModuleなどの別のクラスを追加します。そのGlobalConstantsPopupModuleクラスをapp.module.tsの@NgModuleにインポートします

または

davidが述べたようにInlineEditorModuleをapp.module.tsに移動します。

0
mr.vea

通常、コンポーネントが宣言セクションに追加されていないことを意味します

{
  imports: [],
  providers: [],
  declarations: ["component name"]
}
0
IAfanasov