There have been various studies to try to gauge the different impact on CO2 output of electric versus petrol or diesel vehicles.
There is general agreement that making large car batteries for the electric vehicle greatly adds to the amount of CO2 during the manufacturing of the new vehicle. The electric car may produce twice as much CO2 in its manufacture than the petrol or diesel similar vehicle. The amount required to make the rest of the vehicle apart from the battery is very similar for a comparable vehicle with a different power system.
There is also general agreement that if collectively we scrapped diesel and petrol cars early before the end of their working lives to replace with electric vehicles, that would generate more CO2 as a result of all the extra manufacture.
The degree of saving on running the vehicles is also not a straightforward win for the electric vehicle. Clearly if the electric vehicle is owned and used in a country that does generate all or most of its power from renewable sources there is a a considerable saving on CO2 from use. In practice most of the large vehicle using countries like China, the USA, Germany, UK still depend heavily on gas and coal for generating substantial amounts of power, so there is much less of a CO2 saving from using an electric vehicle. If an electric vehicle is recharged from coal based electricity there could be an increase in CO2 compared to a diesel of petrol machine.
It requires a driver to use the electric vehicle for above average miles each year in a country with a reasonable amount of renewable electricity in the mix for there to be a decent saving of CO2 from electric car purchase and use. When it comes time to get rid of the old battery of an electric vehicle that also generates more CO2 in its disposal. There are also environmental issues about mining the minerals needed for battery production.