I'm using 4.1.0 minified version. Everything works fine until I turn on worker.
No matter which way I call Papa Parse (Papa.parse(file,config) or $(file).parse(config)), I will get this error in my console and then nothing happens (the parser stops).
What kind of environment are you running Papa in? I've seen that reported before; it's probably the same as #114 but we weren't able to pin it down.
I have a hunch now, though. Papa Parse explicitly forbids the use of the byte order mark (\ufeff) as a delimiter, so this character is defined as a variable for convenience (in the minified version, it's e.Papa.BYTE_ORDER_MARK). I just noticed that the minified version seems to replace the sequence \ufeff with the literal byte order mark. Maybe that's problematic.
Could you take a look at position 12,708 in papaparse.min.js - there's the unescaped unicode character there. @tony-cocco, you also had this issue, if you could take a look too I would appreciate it. Try removing that line and the reference to it in the BAD_DELIMITERS array.
If you take out the byte order mark, does it work?
I can't say definitively, but when I stopped passing the papaparse library through minification my issue went away. I would suggest @yokeholy try using the un-minified library and see if that solves his problem.
If possible, might be worthwhile to know what the file that's being parsed looks like.
I tried both minified and un-minified versions. The problem exists whenever worker is on.
I tested with large files (90MB+) as well as a single line string. Quoted strings with comma delimiter.
My environment is Angular+jQuery+BootstrapJS.
One thing through my research pops up: http://stackoverflow.com/questions/3936211/jquery-cannot-read-property-defaultview-of-undefined-error
It seems like the scope has changed. I wonder if it's anything to do with Angular because I'm calling the parser within an Angular controller scope.
I was also using Angular as well. But, the scope changing could still be the cause. My issue came from the grunt task messing with the papa library though.
Apparently, I was using version 3.1.3 of papa. Sorry I can't be of more help.
So I did another test and put the parser caller function outside of my Angular scope, unfortunately, the problem still exists.
@mholt I looked into position 12708, I didn't find the unescaped unicode character there.
is what I have around that position.. I have 4.1.0
I think his suggestion was to remove e.Papa.BYTE_ORDER_MARK from that array. Something you can try till he responds.
Did not do the trick.. :(
That, and also remove the definition of e.Papa.BYTE_ORDER_MARK which should remove that character entirely.
I need your help since I can't seem to reproduce the problem.
@mholt I removed both, still errors out.
Whoops, we both commented at the same time.
Are you sure that the byte order mark character is completely removed? The only other thing I can think of, based on a search for "defaultView of undefined" brings up some jQuery-related stuff on Stack Overflow. Maybe try removing the jQuery stuff (these lines: https://github.com/mholt/PapaParse/blob/master/papaparse.js#L37-L129)
Oh, and I just saw your reply above about what you found on Stack Overflow. I'm not familiar with Angular, so I can't explain why things are breaking with the minified version and using workers. Maybe it has something to do with Angular not playing well in a worker environment or something.
I would recommend using the un-minified version then, as @tony-cocco suggested. That's still so weird...
What if you call Papa from outside the Angular controller scope?
Yes I removed them both..
And trying removing the entire jQuery stuff still doesn't help.
@mholt I did call it outside the Angular controller scope, tried un-minified version. Seems like I'm in bad luck haha
Thanks for trying all that!
You're still getting it with the un-minified code too? That's just bizarre. I can guarantee that error isn't coming from Papa Parse, since defaultView is not defined/found/used anywhere in its code.
What if you try it without Angular? I know it'll probably break your app (just try it), but I'm betting that something there is trying to run code that expects a DOM and there is no DOM in a worker.
Yea that might take a long time :P
BTW, Throughout my js files, I found the word defaultView only in jQuery.
Interesting. Is the minified Papa Parse in the same file as any other library, particularly any that use (or are) jQuery? (This is not uncommon for some build processes, to just combine all the minified libraries into the same file.)
Based on this SO question: http://stackoverflow.com/questions/5453319/undefined-type-error-defaultview-with-basic-jquery
I'm just throwing a wild guess here: maybe the worker is manipulating something that is not applicable to the window object.
@mholt Yes. All these libraries are combined in one file.
@mholt reminded me that when I removed papa from the build chain it was not longer being concatted with others. Try isolating that include.
BINGO! That's it. See this FAQ: http://papaparse.com/faq#combine
This is because a worker thread has to be given an entire JS file - not just a function - to execute. Workers have their own environment and don't even share memory. There's no DOM, and I guarantee that at least one of those other libraries, if not all of them, are not expecting to be executed in a worker thread, devoid of a DOM.
Ahh I feel like an idiot now coz I read that entire FAQ before posting the issue here... hehe
Hmm I guess that's the cause of #114 too. Right @tony-cocco ?
@yokeholy most definitely!
Some glorious day there will be cross-browser support for spinning up workers from code blobs instead of URLs, and then we can kill this confusion.
Ha, yeah. In the meantime, I'll clarify the FAQ and bump that question higher. Good work, team.
Explaining solution to #163 more clearly
More visible explanation of #163 in the docs