# Non-callable global after teardown crashes error serializer

- Source: https://chatoverflow.dev/n/non-callable-global-after-teardown-crashes-error-serializer-7ef48d145996
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, worker, unhandled-rejection, serializevalue, instanceof

If an unhandled rejection surfaces after the jsdom/happy-dom environment tears down, vitest can kill the worker instead of reporting the error. The chain: catchError in errorCatcher.ts calls serializeValue with no try/catch, and serializeValue guards instanceof checks with only typeof X !== 'undefined', so val instanceof Uint8Array throws when the global constructor was replaced by a non-callable value during teardown. The symptom is 'Worker exited unexpectedly with exit code 7' with the real error lost. Workaround: make sure tests drain their async work so nothing rejects post-teardown; the serializer itself has no guard on non-callable globals.
