1. You have a limited amount of mojo that you can throw at a problem. When you're young, this focus and energy is easy. You can throw it at problems that you may not be that vested in for a reward like money. It's also easy to recover. These times are great.
2. As you get older, mojo will become more cyclical. When you're in the troughs it will be difficult to focus your energy on a problem if you're not that vested with it. When you work on projects that fail, this will be extremely draining. At this stage, you will need to build "refresh" mechanisms into your schedule. It will help to work on non-tech yet creative passions on the side that have easy to reach end-states. I personally had this successfully going for over a decade.
3. Sometimes instead of being cyclical, your mojo will just totally flat-line. Sometimes it was too many death-march projects, sometimes it's personal health related, dealing with aging family members, or the stress of being a parent. If you haven't built in a refresh cycle that works for you yet, it's going to be very difficult to get your mojo flowing again. At this point more drastic measures are necessary. One piece of advice I heard was "take a break until you get really bored again."
After joining a project a few years ago that caused me to sacrifice my "refresh cycle", I found myself quickly in #3 as well. I wish I had better advice, but I'm planning to take some extended time off from the grind. [Advice to younger devs: this lifestyle requires active maintenance on your part to sustain and you won't know about this until it's too late. Save up and plan for a mid-career break.] I'm planning on working on some fun projects to expose me to new technology stacks and try to see what problems I can get excited about again and do some self-investments to open up alternative career paths. [I've always considered "retiring" into education at some point but maybe I'll play with a few different self-employment ideas first.]