angular - 类型错误 : Buffer is not a constructor using Angular Material Table Exporter

标签 angular angular-material exporter

我从控制台(firefox)得到的错误

enter image description here

我希望能够使用 mat-table-exporter 导出我的 Angular 应用程序的表( Material 表):https://www.npmjs.com/package/mat-table-exporter .

这是我要重现的堆栈:https://stackblitz.com/edit/mte-demo?file=src%2Fapp%2Fapp.module.ts

我的 HTML 模板:

<button mat-raised-button (click)="exporter.exportTable('xlsx', {fileName:'test', sheet: 'sheet_name', Props: {Author: 'Talha'}})">Excel</button>
<table mat-table [dataSource]="serverArray" multiTemplateDataRows matTableExporter #exporter="matTableExporter">
   .
   .
   .
</table>

我的 package.json

{
  "name": "...",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@amcharts/amcharts4": "4.4.2",
    "@amcharts/amcharts4-geodata": "^4.0.21",
    "@angular/animations": "^8.2.14",
    "@angular/cdk": "^8.2.3",
    "@angular/common": "^8.2.14",
    "@angular/compiler": "^8.2.14",
    "@angular/core": "^8.2.14",
    "@angular/flex-layout": "^6.0.0-beta.18",
    "@angular/forms": "^8.2.14",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "^8.2.14",
    "@angular/platform-browser-dynamic": "^8.2.14",
    "@angular/router": "^8.2.14",
    "@types/paho-mqtt": "^1.0.4",
    "@types/zen-observable": "^0.5.4",
    "angular5-social-login": "^1.0.9",
    "aws-amplify": "^1.1.19",
    "aws-sdk": "^2.401.0",
    "core-js": "^2.6.4",
    "d3": "^5.9.1",
    "expo": "^31.0.6",
    "hammerjs": "^2.0.8",
    "mat-table-exporter": "^1.2.5",
    "moment": "^2.24.0",
    "ngx-facebook": "^2.4.0",
    "ngx-tour-core": "^4.0.1",
    "ngx-tour-md-menu": "^4.0.1",
    "rxjs": "^6.5.4",
    "rxjs-compat": "^6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.19",
    "@angular/cli": "^8.3.22",
    "@angular/compiler-cli": "^8.2.14",
    "@angular/language-service": "^8.2.14",
    "@types/jasmine": "^2.8.16",
    "@types/jasminewd2": "^2.0.6",
    "@types/node": "^10.12.26",
    "codelyzer": "^5.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^2.0.5",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.4.3",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "node-sass": "^4.13.0",
    "protractor": "^5.4.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~3.5.3",
    "webpack": "4.41.5",
    "webpack-cli": "^3.3.10"
  }
}

最佳答案

我的 index.html 文件中有一个脚本:

<script>
    var global = global || window;
    // var Buffer = Buffer || [];
    var process = process || {
      env: { DEBUG: undefined },
      version: []
    };
</script>

注释带有“Buffer”变量的行解决了我的问题。

关于angular - 类型错误 : Buffer is not a constructor using Angular Material Table Exporter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59736453/

相关文章:

java - 如何使用PaymentIntent(Stripe)授权资金?

Angular Material 日期选择器 ISO_8601 格式

html - Angular react 形式控制值只是用户类型?

perl - 为什么我不能在我的 Perl 程序中调用我导出的子例程?

javascript - 将 ThreeJS 场景导出到 STL 文件结果导致文件大小非常大

go - Go 中 Prometheus 的多个端点

angular - 复选框 Angular Material 默认选中

像 Rails 脚手架一样的 Angular 文件生成器

javascript - 根据首字母匹配搜索或过滤数据

html - 从包含 Angular Material 复选框的 div 溢出中删除不必要的滚动条