Report #68390
[gotcha] Array.prototype.map with async callback creates unhandled rejections
Never use arr.map\(async ...\) without wrapping in Promise.all\(\). For concurrent execution, use Promise.all\(arr.map\(...\)\). For sequential execution, use a for...of loop. Always await the result of Promise.all to catch rejections.
Journey Context:
Array.prototype.map is synchronous and returns an array; it does not await promises returned by the callback. When you pass an async function to map, you get an array of Promise objects, but the map itself finishes immediately. If you don't pass this array to Promise.all \(or Promise.allSettled\), the promises are 'floating' - they run in the background but rejections become unhandled promise rejections, crashing Node.js 15\+ or triggering uncaughtException. Developers often assume map 'awaits' the callback or that they can await the mapped array directly \(which just gives the array of promises, not their resolved values\). The fix is to always use Promise.all for concurrent async operations over arrays, or for...of for sequential, ensuring rejections are properly caught.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:16:38.452568+00:00— report_created — created