Batteries were not a viable technology for a variety of reasons until recently. Cost is only one of a number of show-stopping problems with battery technology before circa 20 years ago.
Electric cars were quite popular in the early history of automobiles. It wasn’t until internal combustion development proceeded (mechanical, and resource discovery) that the economics and value proposition flipped.
All the show-stopping problems you mentioned applied to internal combustion before.
Unless electrical generation gets less efficient somehow, the economics are trending back.