developit/workerize-loader

Version 1.2.0 does not export function on worker instance in production mode

leifg opened this issue · 6 comments

leifg commented

I just upgraded to workerize-loader v1.2.0

When the worker instance is created, it does not have the exported functions attached to it.

All this only happens in the production build (development server works fine)

This the the output of console.log(instance) in development server (parseFormula is the exported function):

Worker {onmessage: null, onerror: null, parseFormula: ƒ}
  onerror: null
  onmessage: null
  parseFormula: ƒ ()
__proto__: Worker

When creating a production build, this is the output:

Worker {onmessage: null, onerror: null}
  onerror: null
  onmessage: null
  __proto__: Worker

I have a suspicion it might have something to do with this commit but I don't know enough about the project.

I call the worker like this

the worker function is defined like this

I know I am using the API differently than described in the README, however all of this worked in 1.1.0 and I also converted the examples exactly like described and it still did not export the function in 1.2.0.

I was going to open a ticket too :D, all I can say, is that this is happening to me too. I can't see any exported function in my worker instance. But I could see everything in 1.1.0. That said, happy to see this project maintained, and hope it will work with webpack 5 in near future.

I have the same issue. I forced "workerize-loader": "~1.1.0" in my package.json and it works perfectly fine after the build.

Yikes! I'll take a look.

You could basically do

if node is production build
{ don't export as a local cache object} 
else 
{ export as a local cache object }  

but that is a quick and dirty fix..

A fix has been published in 1.2.1. Thanks all.

Whenever there is a syntax error in the web worker file, you will see a "x is not a function" error first. So if you land here from google, check the web worker file first, problem on workerize was indeed fixed.