To implement Javascript error logging, we need to wrap every module in a try-catch block so that any errors that happen at module initialization time can be caught. (The alternative would be using window.onerror, which has lots of reliability problems.) To do that, the error logging module (which provides the logic to process and report caught exceptions) needs to be loaded before all other modules except the startup modules (which will be dependencies needed to collect system information).
As far as I can see there is no way to do that currently, apart from abusing the `loaderScripts` option in ways in which it probably should not be abused, or maybe relying on extension registration order (which is not well supported in MediaWiki). The simplest way to do it would be to add a hook which can extend `ResourceLoaderStartUpModule::getStartupModules`.
A way to run additional code at the end of the startUp script would be also nice (so that the error logger can be initialized, since mw.config is not ready yet when the tartup modules load), maybe via a JS hook, although that can be worked around.
See [[ https://www.mediawiki.org/wiki/Requests_for_comment/Server-side_Javascript_error_logging | the JS error logging RfC ]] for more context, and T1345 for the current approach.