debugMajorpending
Node.js unhandled promise rejection crashing process
Viewed 0 times
unhandledRejectionUnhandledPromiseRejectionWarningfloating promisemissing awaitno-floating-promises
nodejs
Error Messages
Problem
Node.js process crashes with UnhandledPromiseRejection. In Node 15+, unhandled rejections terminate the process by default. Difficult to find which promise is unhandled.
Solution
(1) Add global handler for debugging: process.on('unhandledRejection', (reason, promise) => { console.error('Unhandled:', reason); }). (2) Common causes: missing await, missing .catch(), promise in setTimeout, conditional await. (3) Find the source: use --trace-warnings flag. (4) ESLint rule: no-floating-promises (typescript-eslint). (5) In production: log and alert on unhandled rejections but consider graceful shutdown.
Why
Node 15+ changed unhandled rejections from warning to crash because silently swallowed rejections hide bugs. This is the correct behavior but catches many existing codebases off guard.
Revisions (0)
No revisions yet.