1

I'm getting

Error: Synchronous http requests are not supported

However I am not doing any http requests. All I am doing is trying to parse a local csv file. Here is my script:

import RNFS from 'react-native-fs';
import Papa from 'papaparse';

const mainBundlePath = RNFS.MainBundlePath;

const path = '/app/src/main/assets/data.csv';

const test = () => {

    Papa.parse(mainBundlePath + path, {
        download: true,
        delimiter: '\t',
        complete: function(results) {
            console.log("results: ", results);
            }
        }
    );

};

export default test;
Hosam Abdelnaser
  • 127
  • 2
  • 11
  • Could you include the exception please (with stack trace). Also view here: https://stackoverflow.com/questions/54333952/make-synchronous-http-request-with-react-native – JRK Mar 14 '19 at 13:27
  • this may help: https://github.com/mholt/PapaParse/issues/507 – Ankit Makwana Mar 14 '19 at 13:34

1 Answers1

0

The problem is solved by a different approach. Instead of reading the file using its path which does not work, I read the file using react-native-fs library after storing the file in the assets folder using the function

readFileAssets

The result of this function is a promise which when resolves returns a string representing the content of the csv file. This string can be passed to

papaparse

to parse it and return back an array of objects.

Hosam Abdelnaser
  • 127
  • 2
  • 11