PapaParse
PapaParse copied to clipboard
ReferenceError: FileReaderSync is not defined on the backend (NodeJS)
Hi,
I'm using Papaparse on the backend using NodeJS, I'm facing some strange error something related firefox while parsing on the backend. Can you please suggest what was wrong ??
Using Postman to trigger POST request and passing the file as a multipart data to API. Attached screenshot reference.
are you using worker mode on server side?
Encountering the same error, but worker in params is at 'false'. Changing its value still give the same error.
Is there something to configure for the backend parsing ?
Same error here:
const inStream = AWS.S3.getObject({ ... }).createReadStream()
Papa.parse(inStream, {
header: true,
worker: false,
step: (...args) => {
console.log(args)
},
complete: (...args) => {
console.log('done',args)
}
})
ReferenceError: FileReaderSync is not defined
at FileStreamer.stream (.../node_modules/papaparse/papaparse.js:681:5)
at Object.CsvToJson [as parse] (.../node_modules/papaparse/papaparse.js:244:19)
...
@pokoli I tried with worker and without worker mode also but no luck, any suggestions ??
It seems that PapaParse is not detecting your stream as a readable so it uses the FileAPI from browser which is not available on Node. This condition is failing:
https://github.com/mholt/PapaParse/blob/master/papaparse.js#L237
I think we should correctly detect the stream you are passing.
Can somebody upload a testing scenario, so I can reproduce it?
I am getting this issue within electron 1.8.2
actually it was an issue I was doing, I was meant to use unparse not parse and that caused the exception.
Having the same problem, but it doesn't seem to be happening on every PC. On my computer with Linux it works both on chrome and firefox. On my co-workers Windows PC, it throws the error
So this may be something related to Windows only. Sorry but as I linux user I can not reproduce.
Did you know if it's specific to some node versions?
Can somebody having the issue post the Node version that they are using?
ole@mki:~/papa$ node --version v9.11.1
I'm also having this issue on Ubuntu 17.10. I'm using this csv file for the test. Here's the code I'm running:
const papa = require('papaparse');
const fs = require('fs');
const c = fs.readFileSync('sample.csv');
const d = papa.parse(c);
Stacktrace:
ReferenceError: FileReaderSync is not defined
at FileStreamer.stream (/home/ole/papa/node_modules/papaparse/papaparse.js:681:5)
at Object.CsvToJson [as parse] (/home/ole/papa/node_modules/papaparse/papaparse.js:245:19)
at Object.<anonymous> (/home/ole/papa/index.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
at startup (internal/bootstrap/node.js:201:19)
This fixes it for me (Just add utf8
when reading the file:
const c = fs.readFileSync('sample.csv', 'utf8');
if you don't add the 'utf8' to the fs.readFileSync, the return value is node Buffer which confuses papaparse.
Interesting - I feel like we should add support to handle a Node Buffer
@dboskovic on #370 we added support for Node Streams, which for me seems equivalent as a Node Buffer
I have the same issue when saving a csv file in Notepad++ and saving it through WinSCP to the server.
Just discovered this lib, and came across the same issue while attempting to parse a CSV stored in an S3 bucket. Upon console logging the returned S3 getObject
response object, the appropriate data is returned in a Node Buffer. Per the suggestions earlier (and following a few related SO suggestions like this one: https://stackoverflow.com/questions/36942442/how-to-get-response-from-s3-getobject-in-node-js), I've tried reformatting with .toString()
and .toString('utf8')
before feeding into Papa, but no luck.
Here's a snippet of what I'm attempting to do:
// initialize empty dict to store parsed returns
let info_obj;
// gen S3 params
let params = {
Bucket: ORIGIN_BUCKET,
Key: srcKey
};
info_obj = Papa.parse(s3.getObject(params, function(err, data) {
if (err) {
console.log(err, err.stack);
} else {
console.log(data);
return data.Body.toString(); // this has been tested adding 'utf8' as well
}
}), {
header: true
});
I've tried disconnecting the getObject()
call from the parse, as well, just to make sure I'm not overlooking something obvious, but I'm new to JS. Any ideas?
@PresBAW have a look at #494 and please open a new issue if the topic is not related
Following the instructions to run the test suite I also get the same error in 8 tests
As a workaround on nodejs you can read the text content of the file itself and use the text instead of the file descriptor API.