Cannot find module DataTablesModule with Angular Datatable in Angular 6
Asked Answered
S

3

5

I am not able to include DataTableModule into our Angular 6 project with datatable. I am using angular cli 6 with datatable. My code is showing error that cannot find module DataTablesModule. I have installed all packages related to datatable and jquery. It is also displaying into node_modules folder but not able to add into app.module.ts.

I am attaching the screenshot below:

Here is my code.

Here is my code

Getting this error in browser

enter image description here

Snowslide answered 12/10, 2018 at 10:35 Comment(2)
have you included the file path in the angular.json?Biforate
yes I have includedSnowslide
B
6

Maybe you are missing any dependency. Follow the steps given in this documentation Angular Datatables

1: Install all the dependencies

  • npm install jquery --save
  • npm install datatables.net --save
  • npm install datatables.net-dt --save
  • npm install angular-datatables --save
  • npm install @types/jquery --save-dev
  • npm install @types/datatables.net --save-dev

2: Add all the dependencies in angular.json

{
  "projects": {
    "your-app-name": {
      "architect": {
        "build": {
          "options": {
            "styles": [
              "node_modules/datatables.net-dt/css/jquery.dataTables.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/datatables.net/js/jquery.dataTables.js"
            ],
            ...
}

3: Import in app-module

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { DataTablesModule } from 'angular-datatables';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,

    DataTablesModule
  ],
  providers: [],
  bootstrap: [ AppComponent ]
})
export class AppModule {}
Biforate answered 12/10, 2018 at 11:14 Comment(2)
followed all these steps, but still angular datatable is showing errorSnowslide
Thank you very much! This is working perfectly for me and I already used it in plenty projects.Cultism
L
0

I had the same problem. I solved it by running the following command in terminal:

ng add angular-datatables

Ref: https://www.npmjs.com/package/angular-datatables/v/9.0.2

Also, This is my complete code if someone want to take a look.

https://github.com/xbox2204/SpringBoot-JPA-Swagger-Angular

Larcenous answered 10/10, 2020 at 13:19 Comment(0)
R
0

I had the same error because i used the angular CLI command: ng add angular-datatables. but when i installed the packages manually, the error was gone. this is the packages :

npm install jquery --save
npm install datatables.net --save
npm install datatables.net-dt --save
npm install angular-datatables --save
npm install @types/jquery --save-dev
npm install @types/datatables.net --save-dev
Regimen answered 1/1, 2022 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.