1

I've been looking all over for a solution to this and I can't figure it out for the life of me...

The sitch: I have a lazy loaded React component which is supposed to parse a CSV file (with PapaParse) which is all built within the create-react-app framework. But for some reason, despite everything saying it should work, when I try to use PapaParse, I get this error:

Error: Script path cannot be determined automatically when Papa Parse is loaded asynchronously. You need to set Papa.SCRIPT_PATH manually.

But since this is bundled with Webpack I have no idea what this script path should be and I've tried setting the path to the PapaParse folder within the project folder structure (i.e. something like ../../node_modules/papaparse) to no avail. I actually got a different error when I put in a path:

papaparse?papaworker:1 Uncaught SyntaxError: Unexpected token <

For some more context, the component in question looks a little like this:

import Papa from 'papaparse';

class Dialog extends React.Component {
    ...
    handleFileChange = () => {
       ...
       Papa.parse(file, config);
       ...
    }
    ...
}

I installed PapaParse via npm, so it should be the latest version, some things go back to 2014-15 where these problems existed, but it's said to have been updated...

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
ainsley26
  • 13
  • 3

1 Answers1

0

Actually, I'm confused, because it works well on both of my projects, hence, React Web App and React Native iOS, Android App.

I imported it like below:

import Papa from 'papaparse/papaparse.min';

Surely, for each project, there are some configs that maybe some libraries work badly. but you maybe can use Node.js path for setting SCRIPT_PATH for Papa:

import path from 'path';

...
Papa.SCRIPT_PATH = path.resolve('/node_modules/papaparse');
...

Or if it has the issue too, then use this link answer for using papaparse directly in your code. that is not recommended.

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
  • If I use `papaparse/papaparse.min` in the import, `parse()` becomes undefined and if I use `resolve()` I unfortunately get another error: `papaparse?papaworker:1 Uncaught SyntaxError: Unexpected token <`, which is just as stumping... In any case, I've now stopped trying to use the worker and will hope that the CSV file isn't large enough to lock up the UI for too long; with this I can parse the results. Cheers for the assist! – ainsley26 Dec 14 '18 at 20:38
  • @ainsley26, please upload a reproduction of your project on a small scale on Gitlab or Github. I wanna help you. – AmerllicA Dec 14 '18 at 20:41