# ReferenceError: Worker is not defined

**URL:** <https://answers.netlify.com/t/referenceerror-worker-is-not-defined/108012>\
**Category:** Support\
**Tags:** serviceworker\
**Created:** [December 5, 2023, 6:31pm UTC](https://answers.netlify.com/t/referenceerror-worker-is-not-defined/108012 "2023-12-05T18:31:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OahMada](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/oahmada/32/56345_2.png) [@OahMada](https://answers.netlify.com/u/OahMada)\
**Post date:** [December 5, 2023, 6:31pm UTC](https://answers.netlify.com/t/referenceerror-worker-is-not-defined/108012/1 "2023-12-05T18:31:59Z")

</div>

PLEASE help us help you by writing a good post!

- we need to know your netlify site name. Example: `gifted-antelope-58b104.netlify.app`
- DNS issues? Tell us the custom domain, tell us the error message! We can’t help if we don’t know your domain.
- Build problems? Link or paste the FULL build log & build settings screenshot

The better the post - the faster the answer.

My app: [https://gilded-bonbon-74b9b9.netlify.app/](https://gilded-bonbon-74b9b9.netlify.app/)

I was trying to offload the file export functionality (PDF, DOCX, etc.) of my app to a web worker for better performance. I’ve used the Comlink library. The worker works as expected, but the Netlify functions I set up would fail with the error message below(Code 502):

“ReferenceError: Worker is not defined  
ReferenceError: Worker is not defined  
at file:///Users/AKIDO/Documents/ReactGPT/.netlify/functions-serve/fetchGrammarMistakes/functions/src/utils/workerInstance.ts:9:6  
at ModuleJob.run (node:internal/modules/esm/module\_job:194:25)”

And the worker logic has nothing to do with the serverless functions that use the Axios library to request the OpenAI API. I don’t know why it tries to access the worker module.

When I comment out the content of the file mentioned in the error message, the execution of the serverless functions goes back to normal.

I could not figure out why. Could any one help?

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [December 6, 2023, 2:30pm UTC](https://answers.netlify.com/t/referenceerror-worker-is-not-defined/108012/2 "2023-12-06T14:30:15Z")

</div>

You say you’re using a web worker, but then pointing to an error in the functions. Why would you need to use Workers inside a Function?

---

<div class="post-metadata">

**Author:** ![OahMada](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/oahmada/32/56345_2.png) [@OahMada](https://answers.netlify.com/u/OahMada)\
**Post date:** [December 6, 2023, 5:26pm UTC](https://answers.netlify.com/t/referenceerror-worker-is-not-defined/108012/3 "2023-12-06T17:26:30Z")

</div>

I don’t use workers in functions. I use workers to generate and download files, such as PDFs. I have no idea why the functions are trying to access worker code.

Below are screenshots of the function implementation and the worker instance setup.

 ![ScreenShot-2023-12-06-at-17.22.09](https://global.discourse-cdn.com/netlify/original/3X/1/a/1a69a9e95bf63bf8dcac74b937ec2a1e5ca04372.png)  
 ![ScreenShot-2023-12-06-at-17.22.45](https://global.discourse-cdn.com/netlify/original/3X/f/0/f0b62565658337012fbf1022f6b2ca47a3f3ceef.png)

---

<div class="post-metadata">

**Author:** ![OahMada](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/oahmada/32/56345_2.png) [@OahMada](https://answers.netlify.com/u/OahMada)\
**Post date:** [December 6, 2023, 5:39pm UTC](https://answers.netlify.com/t/referenceerror-worker-is-not-defined/108012/4 "2023-12-06T17:39:36Z")

</div>

I’ve found the culprit. Functions use a utility called `buildAxiosResponse` from the utils folder, and I have set up an index file to streamline the utilities import. The index file has access to the worker setup. I simply commented out one line, and all the problems were solved.

 ![ScreenShot-2023-12-06-at-17.37.29](https://global.discourse-cdn.com/netlify/original/3X/f/4/f4c4a43611bdc255829e5eb6cb5b00531c338086.png)
