Skip to content

fix: allow importing inside a NodeJS worker with no workerData#58

Open
DerZade wants to merge 1 commit intodevelopit:mainfrom
DerZade:main
Open

fix: allow importing inside a NodeJS worker with no workerData#58
DerZade wants to merge 1 commit intodevelopit:mainfrom
DerZade:main

Conversation

@DerZade
Copy link
Copy Markdown

@DerZade DerZade commented Apr 9, 2026

This PR fixes #57

I added a ?? {} to the threads.workerData destructuring to ensure we have a valid value to destructure.

In addition to that I added a new attribute with a unique name (includes a UUID, so it's basically impossible to set this by accident) to the workerData.
This ensures we can reliably verify that we are running in a worker thread, which was created by web-worker. All other threads will use the mainThread code path (and not the workerThread code path).
Something similar was already suggested by eshaz in #40:

[...]
One enhancement might be to randomize the mod property name. This change assumes that a parent thread won't send a mod property in the workerData...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

can't import web-worker inside a NodeJS worker thread with no workerData

1 participant