首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ExportToCsv不是构造函数

ExportToCsv不是构造函数
EN

Stack Overflow用户
提问于 2020-11-11 03:22:29
回答 1查看 367关注 0票数 1

我正在使用这个导出到- csv 库来导出csv文件的项目,但是它返回一个错误"ExportToCsv不是构造函数“。我不知道有什么问题。希望你能帮我。

代码语言:javascript
运行
复制
 const ExportToCsv  = require('export-to-csv');
 module.exports.ExportToCsv = async (req, res) => {
  try {
   var data = [
   {
   name: 'Test 1',
   age: 13,
   average: 8.2,
   approved: true,
   description: "using 'Content here, content here' "
   },
   {
   name: 'Test 2',
   age: 11,
   average: 8.2,
   approved: true,
   description: "using 'Content here, content here' "
   },
   {
   name: 'Test 4',
   age: 10,
   average: 8.2,
   approved: true,
   description: "using 'Content here, content here' "
   },
 ];

  const options = { 
   fieldSeparator: ',',
   quoteStrings: '"',
   decimalSeparator: '.',
   showLabels: true, 
   showTitle: true,
   title: 'My Awesome CSV',
   useTextFile: false,
   useBom: true,
   useKeysAsHeaders: true,
  };

  const csvExporter = new ExportToCsv(options);

  csvExporter.generateCsv(data);

  }catch(e) {
    console.log(e);
  }
 }
EN

回答 1

Stack Overflow用户

发布于 2020-11-11 03:31:39

使用这些语句中的任何一条导入模块:

const ExportToCsv = require('export-to-csv').ExportToCsv

import { ExportToCsv } from 'export-to-csv';

代码的问题在于您正在导入和引用整个模块,您需要的是模块中的一个特定函数。错误正确地指出,变量ExportToCsv不是构造函数,因为它引用了要导入的模块的整个导出对象。您需要使用的构造函数是从模块导出的对象上的一个属性,因此必须指向该特定属性。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64780026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档