angularangular7ng-modules

How to fix Error: Unexpected value 'DataTableModule' imported by the module 'DashboardModule'. Please add a @NgModule annotation


I converted Angular 4 project to Angular 7. ng serve commands works but after login in an application, it gives error in console "Unexpected value 'DataTableModule' imported by the module 'DashboadModule' . Please add a @NgModule annotation." Application works fine in Angular 4 version. I already have DatatableModule in Imports array definition then what is reason of error coming.

If I ng build --prod. it gives below error -

ERROR in Error during template compile of 'DataTableModule' Function calls are not supported in decorators in 'NgModule' 'NgModule' calls a function at @angular\core\core.ts(194,50).

Here DashboardModule is custom module and DataTableModule is NPM module imported in Dashboard.module.ts. Below is definition -

1) dashboard.module.ts

import { NgModule } from '@angular/core';
import { DashboardComponent } from './dashboard.component';
import { DashboardRoutingModule } from './dashboard-routing.module';
import { SharedModule } from './../shared/shared.module';
import { DataTableModule } from 'angular-4-data-table-bootstrap-4';
import { CommonModule } from '@angular/common';  
import { DashboardService } from './../shared/_services/dashboard.service';

@NgModule({
  imports: [
    SharedModule,CommonModule,DataTableModule,
    DashboardRoutingModule

  ],
  declarations: [
    DashboardComponent
  ],
  providers:[DashboardService]
})
export class DashboardModule { }

2) package.json dependencies

Here version I am using for datatable is - "angular-4-data-table-bootstrap-4": "^0.2.0",

"dependencies": {
    "@agm/core": "^1.0.0-beta.1",
    "@angular/animations": "^7.2.14",
    "@angular/common": "^7.2.14",
    "@angular/compiler": "^7.2.14",
    "@angular/core": "^7.2.14",
    "@angular/forms": "^7.2.14",
    "@angular/http": "^7.2.14",
    "@angular/platform-browser": "^7.2.14",
    "@angular/platform-browser-dynamic": "^7.2.14",
    "@angular/router": "^7.2.14",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5",
    "angular-2-dropdown-multiselect": "^1.9.0",
    "angular-4-data-table-bootstrap-4": "^0.2.0",
    "angular2-multiselect-dropdown": "^2.10.2",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.5.0",
    "file-saver": "^1.3.3",
    "geolib": "^2.0.24",
    "intl": "^1.2.5",
    "moment": "^2.22.1",
    "mydatepicker": "^2.6.3",
    "ng-pick-datetime": "^5.0.0-beta.10",
    "ng2-filter-pipe": "^0.1.10",
    "ngx-chips": "^1.6.5",
    "ngx-inactivity": "^1.0.1",
    "ngx-loading": "^1.0.8",
    "ngx-order-pipe": "^1.1.0",
    "ngx-pagination": "^3.0.1",
    "rxjs": "^6.5.1",
    "rxjs-compat": "^6.5.1",
    "web-animations-js": "^2.3.1",
    "xlsx": "^0.14.3",
    "xlsx-style": "^0.8.13",
    "zone.js": "^0.9.1"
  }

3) dashboard.component.ts

I imported below definition from DataTableModule

import { DataTable, DataTableResource, DataTableTranslations, DataTablePagination } from 'angular-4-data-table-bootstrap-4';

I also verfied its latest version in NPM repository - https://www.npmjs.com/package/angular-4-data-table-bootstrap-4 it is latest and since last 2 years, no latest release at all. I am worried is there any major changes in Angular 7 about module declaration or definition? If yes, what are those? and how to proceed to fix above issue?


Solution

  • I think this would work.

    In app.module.ts:

    Just replace:

    import { DataTableModule } from 'angular-4-data-table';
    

    with

    import { DataTableModule } from 'angular-4-data-table/src/index';