0

编辑:[已解决] 对于阅读本文的任何人,Papa Parse 是浏览器的解析器,而不是 Node.js。Baby Parse 用于 Node.js,但知道它的功能没有那么广泛,并且不能直接从文件中解析,只能从字符串中解析。

papaparse.js文件中,它有这行代码:

xhr = new XMLHttpRequest();

这似乎是导致错误的原因,我不知道如何解决它。

我的代码:

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);
    }
});

任何想法,将不胜感激 :)

4

1 回答 1

3

实际上 PapaParse 现在可以在节点环境中使用: https ://github.com/mholt/PapaParse/blob/master/README.md#papa-parse-for-node

但是,您必须禁用 parse-config 中的“下载”选项,否则库将尝试通过 XMLHttpRequest 加载文件。

于 2019-02-05T14:03:16.520 回答