Solvednode csvtojson fs.exists is not a function

Hi, when I was converting from a csv file, there was an error
"fs.exists is not a function".

It seems that on line 508 in /libs/core/Converter.js, there was something wrong...

I print the variable fs, the result is {}, it's an empty object...

I have no idea about this...many thanks!

This is my code:

const csvFilePath = 'csv.csv'
const csv = require('csvtojson')
csv()
.fromFile(csvFilePath)
.on('json',(jsonObj)=>{

})
.on('done',(error)=>{
    console.log(error)
})

This is the error:
image

node -- 8.6.0
npm -- 5.3.0
csvtojson -- 1.1.9

5 Answers

✔️Accepted Answer

It seems you are trying to use the lib in Browser and "fs" module only exists in nodejs.
For browser, you can use file input to ask your user to choose a file from local and then use FileReader to get content as text. After that, use csv().fromString() to convert the content to JSON.

Also, thanks for your suggestion. Once csvtojson drops support of nodejs 0.10 and nodejs 4, it will update used dependencies accordingly.

More Issues: