javascripttypeerrorpapaparse

Uncaught TypeError: root is undefined papaparse


I have a problem with papaparse in my code, I try to parse a string but is giving me this error:

Uncaught TypeError: root is undefined"

the code is like:

import * as Papa from "../file/papaparse/papaparse.js";
input.onchange = e => {
  var file = e.target.files[0];
  var reader = new FileReader();
  reader.readAsText(file, 'UTF-8');
  reader.onload = readerEvent => {
    let imported = readerEvent.target.result;
    let splittedimp = this.$Papa.parse(imported, {
      "header": true
    })
    console.log(splittedimp);
  }
}

the input.onchange is inside an async function. any idea why this error? The error happen in papaparse file, line 25: root.Papa = factory(); also i didn't use nodejs or jquery, i have simply downloaded the file and imported it into a folder in my project


Solution

  • The problem was that papaparse didn't like the import as. I have added the URL into the script in the HTML page connected to the JS page and now works fine.