[英]TypeError: parse is not a function on csv-parse
I ran into this issue after setting up a simple app using:在使用以下方法设置一个简单的应用程序后,我遇到了这个问题:
Code is:代码是:
const parse = require('csv-parse');
const fs = require('fs');
const results = [];
fs.createReadStream('kepler_data.csv')
.pipe(parse({
comment: "#",
columns: true,
}))
.on('data', (data) => {
results.push(data);
})
.on('error', (err) => {
console.log(err);
})
.on('end', () => {
console.log(results);
console.log('Done!');
});
Running it resulted in:运行它导致:
index.js:7
.pipe(parse({
^
TypeError: parse is not a function
at Object.<anonymous> (/home/jadeye/node.js_workspace/PLANETS-PROJECT/index.js:7:11)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
Searching SO gave similar results but no actual solution.搜索SO给出了类似的结果,但没有实际的解决方案。
Solution was simple.解决方案很简单。 If parse
or any other function is not recognized with node require
, try getting the function itself as:如果parse
或任何其他 function 无法被node require
识别,请尝试将 function 本身获取为:
const { parse } = require('csv-parse');
Something worth noting it the color scheme that emphasizes the difference between the const parse
color = white , and the usage of the function parse
inside pipe
= green .值得注意的是,强调const parse
color = white和pipe
= green中的 function parse
之间的区别的配色方案。
And the colors without error where const { parse }
is green , matchin the const
call.并且 colors 没有错误,其中const { parse }
是green ,匹配const
调用。
Thanks man you saved my day.谢谢你救了我的一天。 One thing I just want to know that which color theme you're using so that I can know the same difference that you found out in this problem.一件事我只想知道您使用的是哪种颜色主题,以便我可以知道您在此问题中发现的相同差异。
Instead of using而不是使用
const { parse } = require('csv-parse');常量 { 解析 } = 要求('csv-parse');
Try Following尝试关注
const { parse } = require("csv-parse");常量 { 解析 } = 要求(“csv 解析”);
get the parse function it self in the csv-parse module by doing const {parse} = require("csv-parse");通过执行 const {parse} = require("csv-parse"); 在 csv-parse 模块中获取解析 function
and call.pipe(parse())和 call.pipe(parse())
What worked for me was changing from "csv-parse" to "csv-parser"对我有用的是从“csv-parse”更改为“csv-parser”
Use this in package.json在 package.json 中使用它
"csv-parser": "^3.0.0"
Instead of:代替:
"csv-parse": "v5.0.4"
const {parse} = require('parse')
instead of const parse = require('parse')
OR尝试const {parse} = require('parse')
而不是const parse = require('parse')
或"csv-parse": "^3.0.0"
of "csv-parse": "^5.3.0"
尝试使用 csv-parse版本,而不是"csv-parse": "^3.0.0"
of "csv-parse": "^5.3.0"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.