【问题标题】:NgxNotification Component fails in production build. Angular 7NgxNotification 组件在生产构建中失败。角 7
【发布时间】:2019-08-09 12:27:42
【问题描述】:

我在 App Module 中使用了 NgxNotificationComponent。这在 ng 服务中运行良好。但是当我尝试使用 ng build --prod 构建应用程序时,它会引发错误。

ERROR in : Type NgxNotificationComponent in /Development/web- 
angular/node_modules/ngx-notification/ngx-notification.d.ts is part of 
the declarations of 2 modules: AppModule in /Development/web- 
angular/src/app/app.module.ts and NgxNotificationModule in 
/Development/web-angular/node_modules/ngx-notification/ngx- 
notification.d.ts! Please consider moving NgxNotificationComponent in 
/Development/web-angular/node_modules/ngx-notification/ngx- 
notification.d.ts to a higher module that imports AppModule in 
/Development/web-angular/src/app/app.module.ts and 
NgxNotificationModule in /Development/web-angular/node_modules/ngx- 
notification/ngx-notification.d.ts. You can also create a new NgModule 
that exports and includes NgxNotificationComponent in /Development/web- 
angular/node_modules/ngx-notification/ngx-notification.d.ts then import 
that NgModule in AppModule in /Development/web- 
angular/src/app/app.module.ts and NgxNotificationModule in 
/Development/web-angular/node_modules/ngx-notification/ngx- 
notification.d.ts

我必须更改节点模块本身还是有任何解决方法。

版本如下

"ngx-notification": "^1.0.5",

开发依赖

"@angular-devkit/build-angular": "~0.11.0",
"@angular/cli": "~7.1.4",

【问题讨论】:

    标签: angular angular7 dev-to-production


    【解决方案1】:

    在你的 app.module.ts 中导入不是声明的 NgxNotificationComponent,而是导入的 NgxNotificationModule。文档不太正确。
    它在生产中有效:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { NgxNotificationModule} from 'ngx-notification';
    
    import { AppComponent } from './app.component';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        NgxNotificationModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    
    

    【讨论】:

      猜你喜欢
      • 2019-05-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 2018-10-13
      相关资源
      最近更新 更多