csvToJson
csvToJson copied to clipboard
I receve "TypeError: fs.readFileSync is not a function"
Actual Behavior
TypeError: fs.readFileSync is not a function
I'm creating my application with Vite and I receive an error when trying to convert CSV to JSON
Steps to Reproduce the Problem
yarn create vite(ReactJS + Typescript)- the hook
const { acceptedFiles, getRootProps, getInputProps } = useDropzone({
accept: { 'text/csv': ['.csv'] },
onDrop: files => {
const file = files[0];
const reader = new FileReader();
reader.onload = () => {
const json = csvToJson
.fieldDelimiter(';')
.getJsonFromCsv(reader.result as string);
console.log(json);
};
reader.readAsText(file);
},
});
- The return when trying to upload
Uncaught TypeError: fs.readFileSync is not a function
at FileUtils.readFile (convert-csv-to-json.js)
Specifications
- Version: Node V20.9.0
"convert-csv-to-json": "^2.44.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"vite": "^5.2.0"
Recommendation
https://vitejs.dev/guide/troubleshooting#module-externalized-for-browser-compatibility