You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
can't import web-worker inside a NodeJS worker thread with no workerData #57
Simply having an import to web-worker inside a NodeJS worker thread with no workerData will result in the following error:
node:internal/event_target:1101
process.nextTick(() => { throw err; });
^
TypeError [Error]: Cannot destructure property 'mod' of 'threads.workerData' as it is undefined.
at workerThread (file:///home/jonas/projects/temp/web-worker-in-worker-test/node_modules/web-worker/src/node/index.js:141:8)
at file:///home/jonas/projects/temp/web-worker-in-worker-test/node_modules/web-worker/src/node/index.js:75:94
at ModuleJob.run (node:internal/modules/esm/module_job:345:25)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:651:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
Node.js v22.19.0
import{parentPort}from'node:worker_threads';importWorkerfrom'web-worker';parentPort.addEventListener('message',e=>{// omitted for brevity, as it is not relevant});
Notes
I saw that #40 tried to fix this issue already, but didn't fix it completely. The fix assumes workerData is set to a value. If it is undefined, we still run into the same issue as described in #40:
[...] When using this library within a worker thread, the workerThread() code is executed, rather than the mainThread() code which creates the worker polyfill.
[...]
This change executes workerThread() only if the mod property is present from the workerData, indicating that it's being executed from a thread created within this library. If mod isn't present, this means that the code is executing within the context of some other worker thread that wasn't created from this library, and it needs to treat the current thread as the main thread by executing mainThread().
Oh yeah and before anyone asks: Why don't you just set workerData as a workaround?
Sadly I don't create the worker myself. My code is running inside a worker created by Nuxt.
Actually, I'm not even importing web-worker. I just want to use the geotiff library, which imports web-worker. So just multiple unlucky circumstances :(
Activity
fix: allow importing inside a NodeJS worker with no workerData
DerZade commentedon Apr 9, 2026
Oh yeah and before anyone asks: Why don't you just set
workerDataas a workaround?Sadly I don't create the worker myself. My code is running inside a worker created by Nuxt.
Actually, I'm not even importing
web-worker. I just want to use thegeotifflibrary, which importsweb-worker. So just multiple unlucky circumstances :(