A part of it is horrible practices and a work culture which incentivizes them.
Who can be happy when the code doesn't work half the time, deployments are manual and happen after work hours, and devs are forced to be "on-call"?
Introduce Test-Driven Development, Domain-Driven Design, Continuous Deployment with Feature Flags, Mutation Testing and actual agile practices (as described in the Agile Manifesto, not the pathetic attempt to rebrand waterfall we have in most companies) to the project and see how happiness rises, along with the project's reliability and maintainability.
Oh, and throw in a 4 day work week, because no one can be mentally productive for that long.
IMO the biggest problem in the industry is that most developers have never seen a project actually following best practices and middle management is invested in making sure it never happens.