ERR_WORKER_UNSERIALIZABLE_ERROR
node
worker_threads
ai_generated
true
Error [ERR_WORKER_UNSERIALIZABLE_ERROR]: Serializing an uncaught exception failed
ID: node/node-worker-thread-crash
85%Fix Rate
88%Confidence
50Evidence
2023-06-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 20 | active | — | — | — |
Root Cause
A worker thread crashed with an error that could not be serialized and sent back to the parent thread via the structured clone algorithm.
genericWorkarounds
-
90% success Add proper error handling in the worker and serialize errors before throwing
In the worker file, wrap logic in try-catch and use parentPort.postMessage({error: err.message}) instead of letting exceptions propagate -
88% success Listen for 'error' and 'exit' events on the Worker instance in the parent
worker.on('error', (err) => { /* handle */ }); worker.on('exit', (code) => { if (code !== 0) /* restart or log */ });Sources: https://nodejs.org/api/worker_threads.html#event-error
Dead Ends
Common approaches that don't work:
-
Wrapping the entire worker in a try-catch without handling the error event on the parent
80% fail
Uncaught exceptions in worker threads are not caught by try-catch in the parent; you must listen for the 'error' event on the Worker instance
-
Restarting the worker in an infinite loop without addressing the root cause
75% fail
Creates a crash loop that consumes resources and masks the underlying bug
Error Chain
Preceded by:
Frequently confused with: