TL;DR: Are you "down-resing" your project during export eg. from 4K to 1080p HD? If so, try "down-resing" before exporting. It's an unconventional solution which I haven't seen suggested anywhere else, but it worked for me and I haven't had any issues since.
I will offer a solution here, but first I have to say that I started having this same problem on my late-2012 iMac with the following specs (similar to yours):
- FCPX Version 10.4.8
- iMac (27-inch, Late 2012)
- 3.4 GHz Quad-Core Intel Core i7
- 16 GB 1600 MHz DDR3
- NVIDIA GeForce GTX 680MX 2 GB
Up until about a month ago, I didn't have any problems with exporting my project to YouTube. Suddenly, about 2 minutes into exporting, my iMac crashed and rebooted. This happened over and over. I tried many solutions offered by the Apple Support Community (including those provided in this thread) and various Google results. None seemed to work. I then uninstalled and reinstalled FCPX. Crash. I reinstalled MacOS Catalina (because the problem started after I upgraded from Mojave and I wasn't able to roll it back). Crash.
After wracking my brain over this for several days trying to figure out which variable(s) had changed, it suddenly occurred to me that I was previously importing and rendering all files as 1080p HD (1920x1080) and exporting as such. For my latest project, I decided to import and work on the files in 4K and export to YouTube as 1080p HD. CRASH! CRASH! CRASH! I converted the project to 1080p HD, and BOOM BABY! it worked! I haven't had any problems since then.
So, it appears my iMac is not able to handle the conversion process during export. However, my MacBook Pro (15", 2017, 3.1 GHz Quad-Core Intel Core i7, 16 GB 2133 MHz LPDDR3, Intel HD Graphics 630 1536 MB) is.
Give my suggestion and try and let us know if it worked for you.
Good luck!
Chris