javascript - XMLHttpRequest is not defined - Papa parse - Stack Overflow

EDIT: [SOLVED] For anyone who reads this, Papa Parse is a parser for the browser, not Node.js. Baby Par

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,
    plete: function(results) {
        data = results;
        console.log(data);
    }
});

Any ideas would be appreciated :)

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,
    plete: function(results) {
        data = results;
        console.log(data);
    }
});

Any ideas would be appreciated :)

Share Improve this question edited Jul 28, 2016 at 19:34 FF5Ninja asked Jul 28, 2016 at 18:24 FF5NinjaFF5Ninja 5252 gold badges7 silver badges17 bronze badges 3
  • 7 Sounds like you're trying to run browser Javascript in Node.js. You can't do that. – SLaks Commented Jul 28, 2016 at 18:27
  • 1 you could also use babyparse that is monjs github./Rich-Harris/BabyParse – Daniel Lizik Commented Jul 28, 2016 at 18:30
  • Yup, you're absolutely right. Papa parse is for the browser, and I just found out Baby Parse is for node. I see the issue now, thanks! – FF5Ninja Commented Jul 28, 2016 at 18:31
Add a ment  | 

1 Answer 1

Reset to default 5

actually PapaParse can be used in a node environment now: https://github./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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744870472a4598230.html

相关推荐

  • javascript - XMLHttpRequest is not defined - Papa parse - Stack Overflow

    EDIT: [SOLVED] For anyone who reads this, Papa Parse is a parser for the browser, not Node.js. Baby Par

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信