property

ModuleGraphOptions.onError

onError?: (error: unknown, kind: 'uncaughtException' | 'unhandledRejection') => void

Called with the uncaught exceptions and unhandled rejections that happen in this graph's context, instead of the process-wide uncaughtException / unhandledRejection handling. kind says which.

An error is the graph's when it happens in the graph's context, whoever wrote the code that threw: the graph's modules and what they start, and what the host calls through ModuleGraph.run. A function of the graph's that the host calls directly runs in the host's context, and its errors are the host's. The promise ModuleGraph.import returns is its caller's.

The handler runs in the context the graph was made in, so what it throws or rejects is that context's: the host's, when the host made the graph.

Without an onError, errors go to the onError of the graph in whose context this graph was made, and to the process-wide path when the host made it.