can't import web-worker inside a NodeJS worker thread with no workerData
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 62/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Calme
- Stack technique
- javascript, node.js
- Domaine
- backend
Piste de recherche
Exécutez d’abord la reproduction fournie avec main.js et worker.js, puis examinez src/node/index.js autour de workerThread à la ligne 141 ainsi que le chemin d’importation associé. C’est terminé lorsque l’importation de web-worker dans un worker thread NodeJS sans lien, avec workerData undefined, ne lève plus d’exception, tandis que le comportement propre de worker-thread de la bibliothèque reste intact.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
Reproduction
main.js
import { Worker } from 'node:worker_threads';
const worker = new Worker('./worker.js', {});
setTimeout(() => worker.terminate(), 1000);
worker.js
import { parentPort } from 'node:worker_threads';
import Worker from '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 themainThread()code which creates the worker polyfill.
[...]
This change executesworkerThread()only if themodproperty is present from theworkerData, indicating that it's being executed from a thread created within this library. Ifmodisn'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 executingmainThread().
- Langage dominant
- JavaScript
- Étoiles
- 1.2k
- Forks
- 57
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de developit/web-worker
-
Difficulté 3/5 1-2 jours Accessibilité débutants 52/100
developit/web-worker#55 · 1 commentaire · 5 réactions ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 30/100
developit/web-worker#51 · 1 commentaire ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 42/100
developit/web-worker#30 · 4 commentaires · 9 réactions ·
-
Register submodule Ouverteenhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 35/100
developit/web-worker#27 ·
-
Add support for SharedWorker Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
developit/web-worker#25 ·
Toutes les issues de developit/web-worker
Issues similaires
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
Improve Title Support Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
georgestephanis/p2026#40 ·
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Margaret-Petersen/food-delivery-app-clone-react-native#1981 ·