Unable to restart - invariant() failure

If MongoDB is shutdown during the building of a large index. Every time the database is restarted it gets:

“msg”:“\n\n***aborting after invariant() failure\n\n”

If --repair is used it has the same response. Deleting the lock file does not help either. I have found no way to get the database back up other then deleting the catalog so that all collections are moved to local as orphan collections and then renaming them across and rebuilding indexes.

This issue happens in Mongo 5.0 onwards to the latest version.

Does anyone have a solution to solve this?