XMLHttpRequest is not defined - Papa parse

你。 提交于 2020-01-17 03:01:25

问题


EDIT: [SOLVED] For anyone who reads this, Papa Parse is a parser for the browser, not Node.js. Baby Parse is used for Node.js, but know that it isn't as extensive in its functionality and can't parse straight from a file, only from a string.

In the papaparse.js file, it has this line of code:

xhr = new XMLHttpRequest();

This seems to be causing the error and I'm not sure how to get around it.

My code:

var Papa = require('papaparse');
var data;

process.argv.forEach(function(val, index, array) {
    console.log(index + ': ' + val);
});
var file = process.argv[2];
console.log("File: " + file);


// Parse the file
Papa.parse(file, {
    header: true,
    download: true,
    dynamicTyping: true,
    complete: function(results) {
        data = results;
        console.log(data);
    }
});

Any ideas would be appreciated :)


回答1:


actually PapaParse can be used in a node environment now: https://github.com/mholt/PapaParse/blob/master/README.md#papa-parse-for-node

however, you have to disable the "download" option in the parse-config, since otherwise the library will attempt to load the file via XMLHttpRequest.



来源:https://stackoverflow.com/questions/38644080/xmlhttprequest-is-not-defined-papa-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!