The new electric cars are more modular.
And remember, locomotives use electric motors to drive themselves. The diesel just charges them.
IIRC, the diesel drives a generator which in turn drives an a.c. motor. The reason being that at low rpm’s an electric motor produces much more torque.