Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I receve "TypeError: fs.readFileSync is not a function" #57

Open
MmatheusF opened this issue Apr 12, 2024 · 0 comments
Open

I receve "TypeError: fs.readFileSync is not a function" #57

MmatheusF opened this issue Apr 12, 2024 · 0 comments

Comments

@MmatheusF
Copy link

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

  1. yarn create vite (ReactJS + Typescript)
  2. 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);
    },
  }); 
  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant