question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Window is not defined error when using worker

See original GitHub issue

Hi,

I am currently using Papa Parse with npm, which I then import into my React file using:

import * as Papa from 'papaparse';

I’m using an upload button on the front-end to pass the file to React and using Papa Parse to parse CSV files. All works fine with small files but I realized with large ones, I’d need to use a worker or else the browser crashes. However adding the worker parameter is causing an error in the console. See below for reference:

Papa.parse( file, {
			worker        : true,
			header        : false,
			skipEmptyLines: 'greedy',
			step          : function( results ) {
				console.log( 'Result:', results.data );
			},
			complete      : function( results ) {
				console.log('Complete', results);
			}
		} );

Without the worker, the error goes away - any idea how to troubleshoot this? Is it my local environment or the way Papa Parse is set up in my project? Thanks!

If it helps, the CSV file I’m testing with is the “large file” from Papa Parse’s “local file” demo here: https://www.papaparse.com/demo

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pokolicommented, Oct 19, 2018

Probably you need to set the PAPA_SCRIPT path variable as explained on the Can Papa Parse be loaded asynchronously (after the page loads)? section of our faq

0reactions
jjechcommented, Apr 19, 2019

I’m now successfully using worker with PapaParse.

Here are the final steps that worked for me.

  1. Copied papaparse.js from node_modules/papaparse/ to my main app directory.
  2. Added the following lines to both App.js and index.js

var Papa = require(“papaparse”); Papa.SCRIPT_PATH = “./papaparse.js”;

Read more comments on GitHub >

github_iconTop Results From Across the Web

"window is not defined" service worker - Stack Overflow
I was writing the code: // App install banner window.addEventListener('beforeinstallprompt', function(e) { e.
Read more >
"not defined" window in web worker. Is this a bug?
I am running into an issue trying to load a model into a web-worker via the indexedDB. Specifically, I am getting a ReferenceError:...
Read more >
window is not defined when using Workers · Issue #153 - GitHub
I get an error as in title. I thought this library was supposed to be compatible with node.js. So why use window? Actually,...
Read more >
How to solve "window is not defined" errors in React and Next.js
First solution: typeof​​ Because typeof won't try to evaluate "window", it will only try to get its type, in our case in Node....
Read more >
Uncaught ReferenceError: window is not defined - Workers
Look in the library that you're importing then - your code is running in a server-side context, like Node, not in a user's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found