Hi I have been attempting to convert a CSV to a JSON using csvtojson module. I have been trying to follow the steps outlined here but I am encountering an unusual error saying Uncaught Error: Cannot find module 'fs'
I am beginning by importing the module
import csv from "csvtojson";
I couldn't find any documentation on the csvtojson docs page stating that I should install and import a module fs (although I have attempted to do this).
The function I am running looks like this:
handleFiles = () => {
let newfile = this.refs.file.files[0];
let reader = new FileReader();
csv({
ignoreEmpty: true,
headers: ["Year", "Month", "Name"]
})
.fromFile(newfile.name)
.then((jsonObj) => {
console.log(jsonObj);
})
}
the input looks like this:
<input ref="file" type="file" onChange={this.handleFiles} filetypes={'.csv'}>
</input>
The only issue I can see is possibly from this line .fromFile(newfile.name)
The docs state to use .fromFile(<path to csv file>)
but the path is not always known. Instead I am using the file name. Nevertheless the error I am getting doesn't seem to be related to this.