1

I have installed it in my project folder with:

npm install papaparse --save

and included in my main.js file:

const Papa = require('papaparse')

My package.json shows papaparse as a dependancy. However I get the following error:

index.html:77 Uncaught ReferenceError: Papa is not defined
    at parseStuff (index.html:77)
    at HTMLInputElement.onclick (index.html:14)

The function:

function parseStuff(){
    Papa.parse('d:\\shite.csv', {
        download: true,
        complete: function(results) {
            console.log("Finished", results.data);
        }
    });

Only just started using Electron for a quick project (and javascript isn't my native language) so forgive me if it's something obvious.

WarmCat
  • 11
  • 3
  • Due to my inexperience with node or electron, I wasn't aware that I also needed to add the following to my html file, it wasn't obvious. `var Papa = require('papaparse');` – WarmCat Nov 16 '18 at 21:22

2 Answers2

0
var Papa = require('papaparse');

The above needs to be added to the .html file.

Hopefully will help another electron newbie!

WarmCat
  • 11
  • 3
  • Right, you need to require the module wherever it's being used. If your function is in a ` – pushkin Nov 16 '18 at 21:50
  • Makes sense now, but at the time I assumed that in the `main.js` was enough, and that any `require` would be inherited. – WarmCat Nov 18 '18 at 10:49
0

import Papa from "papaparse";

Black Beard
  • 1,130
  • 11
  • 18
  • Although very short code-snippet, I would see as valid answer ... if you please __provide an explanation__ and/or link to reference docs like: [import - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) – hc_dev Mar 04 '21 at 19:30
  • And I doubt that this simple `import` will do for _Electron_ the same like for other web-frameworks - see similar question: [javascript - How to import PapaParse with Browserify to inject into a controller? - Stack Overflow](https://stackoverflow.com/questions/40439527/how-to-import-papaparse-with-browserify-to-inject-into-a-controller – hc_dev Mar 04 '21 at 19:33