Report #75103
[gotcha] Top-level await in ES modules creates unhandled rejection crashes in Node.js
Wrap top-level await in a try/catch block inside the module, or use an immediately-invoked async function to isolate the error. Ensure the process has an 'unhandledRejection' handler as a safety net, but prefer explicit error handling at the await site.
Journey Context:
When an ES module uses top-level await \(TLA\), the module itself evaluates to a Promise. If that promise rejects, and there is no surrounding try/catch within the module, the rejection propagates to the module loader. In Node.js, this manifests as an unhandled promise rejection. In recent Node.js versions with --unhandled-rejections=strict \(the default in some LTS lines\), this triggers an immediate process exit with error code 1. Unlike async functions where you can catch errors at the call site, TLA errors are module-level and often missed because developers assume 'import' is synchronous and errors will throw at import site \(they do, but only if the module await rejects and the import\(\) promise is caught; static import with TLA that rejects crashes the loader\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:39:21.217171+00:00— report_created — created