使用角度数据表时遇到错误

问题描述 投票:0回答:5

我使用的是 ubuntu 20.04,npm 6.14.15,node v14.17.2 和 Angular CLI:11.2.14。我尝试使用 Angular-datatables 模块在我的工作目录中创建数据表。

为了使用这个 Angular-Datatables 模块,我安装了以下软件包。

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

在我运行服务器后,Angular cli 抛出以下错误。

错误信息

Error: node_modules/angular-datatables/src/angular-datatables.directive.d.ts:39:21 - error TS2694: Namespace '"/home/nanthu/codoid-projects/dmk-youth-wing/DMK-Youth-Wing-Website/node_modules/@angular/core/core"' has no exported member 'ɵɵFactoryDeclaration'.

39     static ɵfac: i0.ɵɵFactoryDeclaration<DataTableDirective, never>;
                       ~~~~~~~~~~~~~~~~~~~~


Error: node_modules/angular-datatables/src/angular-datatables.directive.d.ts:40:21 - error TS2694: Namespace '"/home/nanthu/codoid-projects/dmk-youth-wing/DMK-Youth-Wing-Website/node_modules/@angular/core/core"' has no exported member 'ɵɵDirectiveDeclaration'.

40     static ɵdir: i0.ɵɵDirectiveDeclaration<DataTableDirective, "[datatable]", never, { "dtOptions": "dtOptions"; "dtTrigger": "dtTrigger"; }, {}, never>;
                       ~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/angular-datatables/src/angular-datatables.module.d.ts:13:21 - error TS2694: Namespace '"/home/nanthu/codoid-projects/dmk-youth-wing/DMK-Youth-Wing-Website/node_modules/@angular/core/core"' has no exported member 'ɵɵFactoryDeclaration'.

13     static ɵfac: i0.ɵɵFactoryDeclaration<DataTablesModule, never>;
                       ~~~~~~~~~~~~~~~~~~~~


Error: node_modules/angular-datatables/src/angular-datatables.module.d.ts:[93m14:21 - error TS2694: Namespace '"/home/nanthu/codoid-projects/dmk-youth-wing/DMK-Youth-Wing-Website/node_modules/@angular/core/core"' has no exported member 'ɵɵNgModuleDeclaration'.

14     static ɵmod: i0.ɵɵNgModuleDeclaration<DataTablesModule, [typeof i1.DataTableDirective], [typeof i2.CommonModule], [typeof i1.DataTableDirective]>;
                       ~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/angular-datatables/src/angular-datatables.module.d.ts:15:21 - error TS2694: Namespace '"/home/nanthu/codoid-projects/dmk-youth-wing/DMK-Youth-Wing-Website/node_modules/@angular/core/core"' has no exported member 'ɵɵInjectorDeclaration'.

15     static ɵinj: i0.ɵɵInjectorDeclaration<DataTablesModule>;

如何解决此问题以获取 Angular 数据表?

package.json

{
  "name": "dmk-youth-wing-website",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~11.2.8",
    "@angular/cdk": "^12.2.5",
    "@angular/common": "~11.2.8",
    "@angular/compiler": "~11.2.8",
    "@angular/core": "~11.2.8",
    "@angular/forms": "~11.2.8",
    "@angular/localize": "~11.2.8",
    "@angular/platform-browser": "~11.2.8",
    "@angular/platform-browser-dynamic": "~11.2.8",
    "@angular/router": "~11.2.8",
    "@fortawesome/fontawesome-svg-core": "^1.2.36",
    "@ng-bootstrap/ng-bootstrap": "^9.1.3",
    "@ng-select/ng-select": "^7.2.0",
    "@ngx-translate/core": "^13.0.0",
    "@ngx-translate/http-loader": "^6.0.0",
    "angular-datatables": "^13.0.0",
    "bootstrap": "^4.5.0",
    "datatables.net": "^1.11.3",
    "datatables.net-dt": "^1.11.3",
    "jquery": "^3.6.0",
    "ngx-slick-carousel": "^0.5.1",
    "ngx-spinner": "^11.0.1",
    "ngx-toastr": "^14.1.1",
    "rxjs": "~6.6.0",
    "slick-carousel": "^1.8.1",
    "subsink": "^1.0.2",
    "tslib": "^2.0.0",
    "zone.js": "~0.11.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1102.7",
    "@angular/cli": "~11.2.7",
    "@angular/compiler-cli": "~11.2.8",
    "@types/datatables.net": "^1.10.21",
    "@types/jasmine": "~3.6.0",
    "@types/jquery": "^3.5.8",
    "@types/node": "^12.11.1",
    "@types/owlcarousel": "^1.3.5",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.1.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.1.5"
  }
}

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "cli": {
    "analytics": false
  },
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "DMK-Youth-Wing-Website": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/DMK-Youth-Wing-Website",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss",
              "node_modules/slick-carousel/slick/slick.scss",
              "node_modules/slick-carousel/slick/slick-theme.scss",
              "node_modules/datatables.net-dt/css/jquery.dataTables.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/slick-carousel/slick/slick.min.js",
              "node_modules/datatables.net/js/jquery.dataTables.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "DMK-Youth-Wing-Website:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "DMK-Youth-Wing-Website:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "DMK-Youth-Wing-Website:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "DMK-Youth-Wing-Website:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "DMK-Youth-Wing-Website:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "DMK-Youth-Wing-Website"
}
node.js angular npm datatables angular-datatables
5个回答
3
投票

我也有同样的问题。您需要卸载datatable并安装比您已安装的版本更低的版本。在我们的例子中,数据表版本都是 13.0.0。我卸载了这个并安装了较低版本。

npm uninstall angular-datatables
npm install [email protected]
npm start

2
投票

今天,2022 年 2 月 26 日,我在最新版本的 Angular 中遇到了同样的问题,我通过直接在 package.json 中添加该版本来解决它,因为卸载命令没有删除 node_modules 中的包

enter image description here


1
投票

我在使用

npm install angular-datatables
时遇到了同样的问题,它是安装数据表版本
"angular-datatables": "^13.1.0"

所以只需将

angular-datatables
的版本降级为
6.0.0

安装特定版本的

angular-datatables

  1. 删除
    node_modules
  2. npm install [email protected]

0
投票

转到 angular.json 并降级到大多数人正在使用的版本

这对我有用 “角度数据表”:“^13.1.0”, "引导程序": "^5.2.1", "datatables.net": "^1.12.1", "datatables.net-bs5": "^1.11.3", “datatables.net-dt”:“^1.11.3”,


0
投票

来自 triumlabs 的答案 https://github.com/l-lin/angular-datatables/issues/1248 对我有用。 更具体地说,在我的上下文中,我打开了 package.json 并将 "@types/datatables.net": "^1.10.21" 更改为 "@types/datatables.net": "~1.10.21" 和有效。 我希望它对你有用!!

© www.soinside.com 2019 - 2024. All rights reserved.