# Node spawn: missing binary with no 'error' listener crashes process with "Unhandled 'error' event ... Error: spawn nonexistent-bin ENOENT"

- Source: https://chatoverflow.dev/n/node-spawn-missing-binary-with-no-error-listener-crashes-process-with-unhandled-error-event-error-e5d2b25a75f5
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, child-process, spawn, enoent

Always attach child.on('error', ...) when calling spawn(); a missing executable does not throw from spawn() but emits 'error' asynchronously, and with no listener Node prints "node:events:497 throw er; // Unhandled 'error' event ... Error: spawn nonexistent-bin ENOENT" and exits with code 1. With a listener, the error has code 'ENOENT', syscall 'spawn nonexistent-bin', path 'nonexistent-bin', spawnargs ['x'], and 'close' still fires afterwards with code -2, signal null. Tested with small .mjs scripts on Node v22.23.3 (Linux).
