I usually agree with you, but my experience with this has been completely different. First, the thing that makes a great developer is not the technology stack, but understanding of basic engineering principles and how to learn a new stack in a way that aligns with those principles (today, that isn't easy, because many newer frameworks actually fight good design). This knowledge transfers no matter where you go.
Second, you have to be proactive and look out for yourself _and_ the company by "stealing" time early in the project when you're not expected to be productive anyway to learn techniques that will save you time throughout the project. This pays for itself quickly, to the extent usually no one notices. It also gives you extra time to learn even more techniques that save you time. Before you know it, you're an expert in place _and_ have time to learn other things as well. You'll also be better than most "I" shaped developers that specialized in that technology within a few months. Do this a few times, and your skillset will be amazing.
Third, there are always places hiring for old technologies. You won't die if you're not current. I recently worked on a project converting an old website built in ASP to React, where I used skills I haven't called on in 15 years. There are systems out there in Cobol still. It's common for large companies to have multiple projects running in multiple tech stacks. Get hired by a large company using your less-fashionable skills, and there's a good chance that at some point you'll be asked to work on a project in a more-fashionable tech stack. At these companies, older codebases are usually quite crufty so they need to hire in maintenance programmers. If you followed my advice to learn basic good engineering, you won't fail to impress. These companies always churning on R & D, so opportunities to change stacks are common. They will pay you to learn, and since you already know how to learn deeply, quickly, you'll do great. The downside of doing this is most places will not be willing to accept your 6 months with technology A is worth most peoples' 2 years with it, so YMMV.