New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When use worker, I get Uncaught TypeError: Cannot read property 'defaultView' of undefined #163

Closed
yokeholy opened this Issue Jan 21, 2015 · 27 comments

Comments

Projects
None yet
4 participants
@yokeholy

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).

@mholt

This comment has been minimized.

Show comment
Hide comment
@mholt

mholt Jan 21, 2015

Owner

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?

Owner

mholt commented Jan 21, 2015

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?

@mholt mholt added the under review label Jan 21, 2015

@tony-cocco

This comment has been minimized.

Show comment
Hide comment
@tony-cocco

tony-cocco Jan 21, 2015

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 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.

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

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.

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.

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

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.

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.

@tony-cocco

This comment has been minimized.

Show comment
Hide comment
@tony-cocco

tony-cocco Jan 21, 2015

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.

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.

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

So I did another test and put the parser caller function outside of my Angular scope, unfortunately, the problem still exists.

So I did another test and put the parser caller function outside of my Angular scope, unfortunately, the problem still exists.

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

@mholt I looked into position 12708, I didn't find the unescaped unicode character there.
e.Papa.BAD_DELIMITERS=["\r","\n",'"',e.Papa.BYTE_ORDER_MARK];e.Papa.WORKERS_SUPPORTED=!!e.Worker;
is what I have around that position.. I have 4.1.0

@mholt I looked into position 12708, I didn't find the unescaped unicode character there.
e.Papa.BAD_DELIMITERS=["\r","\n",'"',e.Papa.BYTE_ORDER_MARK];e.Papa.WORKERS_SUPPORTED=!!e.Worker;
is what I have around that position.. I have 4.1.0

@tony-cocco

This comment has been minimized.

Show comment
Hide comment
@tony-cocco

tony-cocco Jan 21, 2015

I think his suggestion was to remove e.Papa.BYTE_ORDER_MARK from that array. Something you can try till he responds.

I think his suggestion was to remove e.Papa.BYTE_ORDER_MARK from that array. Something you can try till he responds.

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

Did not do the trick.. :(

Did not do the trick.. :(

@mholt

This comment has been minimized.

Show comment
Hide comment
@mholt

mholt Jan 21, 2015

Owner

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.

Owner

mholt commented Jan 21, 2015

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.

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

@mholt I removed both, still errors out.

@mholt I removed both, still errors out.

@mholt

This comment has been minimized.

Show comment
Hide comment
@mholt

mholt Jan 21, 2015

Owner

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)

Owner

mholt commented Jan 21, 2015

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)

@mholt

This comment has been minimized.

Show comment
Hide comment
@mholt

mholt Jan 21, 2015

Owner

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?

Owner

mholt commented Jan 21, 2015

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?

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

Yes I removed them both..
And trying removing the entire jQuery stuff still doesn't help.

Yes I removed them both..
And trying removing the entire jQuery stuff still doesn't help.

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

@mholt I did call it outside the Angular controller scope, tried un-minified version. Seems like I'm in bad luck haha

@mholt I did call it outside the Angular controller scope, tried un-minified version. Seems like I'm in bad luck haha

@mholt

This comment has been minimized.

Show comment
Hide comment
@mholt

mholt Jan 21, 2015

Owner

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.

Owner

mholt commented Jan 21, 2015

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.

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

Yea that might take a long time :P
BTW, Throughout my js files, I found the word defaultView only in jQuery.

Yea that might take a long time :P
BTW, Throughout my js files, I found the word defaultView only in jQuery.

@mholt

This comment has been minimized.

Show comment
Hide comment
@mholt

mholt Jan 21, 2015

Owner

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.)

Owner

mholt commented Jan 21, 2015

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.)

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

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.

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.

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

@mholt Yes. All these libraries are combined in one file.

@mholt Yes. All these libraries are combined in one file.

@tony-cocco

This comment has been minimized.

Show comment
Hide comment
@tony-cocco

tony-cocco Jan 21, 2015

@mholt reminded me that when I removed papa from the build chain it was not longer being concatted with others. Try isolating that include.

@mholt reminded me that when I removed papa from the build chain it was not longer being concatted with others. Try isolating that include.

@mholt

This comment has been minimized.

Show comment
Hide comment
@mholt

mholt Jan 21, 2015

Owner

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.

Owner

mholt commented Jan 21, 2015

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.

@mholt mholt closed this Jan 21, 2015

@mholt mholt added discussion and removed under review labels Jan 21, 2015

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

Ahh I feel like an idiot now coz I read that entire FAQ before posting the issue here... hehe

Ahh I feel like an idiot now coz I read that entire FAQ before posting the issue here... hehe

@yokeholy

This comment has been minimized.

Show comment
Hide comment
@yokeholy

yokeholy Jan 21, 2015

Hmm I guess that's the cause of #114 too. Right @tony-cocco ?

Hmm I guess that's the cause of #114 too. Right @tony-cocco ?

@tony-cocco

This comment has been minimized.

Show comment
Hide comment
@tony-cocco

tony-cocco Jan 21, 2015

@yokeholy most definitely!

@yokeholy most definitely!

@bluej100

This comment has been minimized.

Show comment
Hide comment
@bluej100

bluej100 Jan 21, 2015

Contributor

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.

Contributor

bluej100 commented Jan 21, 2015

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.

@mholt

This comment has been minimized.

Show comment
Hide comment
@mholt

mholt Jan 21, 2015

Owner

Ha, yeah. In the meantime, I'll clarify the FAQ and bump that question higher. Good work, team.

Owner

mholt commented Jan 21, 2015

Ha, yeah. In the meantime, I'll clarify the FAQ and bump that question higher. Good work, team.

mholt added a commit that referenced this issue Jan 21, 2015

nathancahill added a commit to nathancahill/PapaParse that referenced this issue May 22, 2015

mholt added a commit that referenced this issue May 22, 2015

Merge pull request #210 from nathancahill/clarify-worker-docs
More visible explanation of concatinating issue (#163) in the docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment