While both also mean serious, ernsthaft has some other meanings than ernst, and they are mostly not interchangeable.
Example for when you can not use ernst:
Willst Du mir ernsthaft erzählen, dass ... (are you really trying to tell me ...)
Example for when you can not use ernsthaft:
Meinst Du das ernst? (Are you serious?)
Generally, you should be able to replace ernstaft by im Ernst, while you can for the most part not exchange ernst with im Ernst (with one exception maybe being Meinst Du das ernst/im Ernst?, where the im Ernst variant is in my experience used rarely, mostly in spoken German).
DWDS tells us:
ernst: not in a light mood, threatening
ernsthaft: haunting, grave, sincere