ReferenceError: Worker is not defined

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/

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?

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?

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.


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.