can't import web-worker inside a NodeJS worker thread with no workerData
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 62/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- javascript, node.js
- Ambito
- backend
Direzione di ricerca
Esegui prima la riproduzione fornita con main.js e worker.js, quindi esamina src/node/index.js intorno a workerThread alla riga 141 e il relativo percorso di importazione. Il lavoro è completato quando l’importazione di web-worker all’interno di un worker thread NodeJS non correlato con workerData undefined non genera più un’eccezione, mentre il comportamento del worker-thread della libreria rimane invariato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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().
- Lingua principale
- JavaScript
- Stelle
- 1.2k
- Fork
- 57
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di developit/web-worker
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
developit/web-worker#55 · 1 commento · 5 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
developit/web-worker#51 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
developit/web-worker#30 · 4 commenti · 9 reazioni ·
-
Register submodule Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
developit/web-worker#27 ·
-
Add support for SharedWorker Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
developit/web-worker#25 ·
Tutte le issue di developit/web-worker
Issue simili
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Improve Title Support Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
georgestephanis/p2026#40 ·
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Margaret-Petersen/food-delivery-app-clone-react-native#1981 ·