Several studies on this topic show, among other things, that it depends on mileage. Previously, what put the electric car at a disadvantage was battery recycling. When you had to recycle the battery after 10 or 20 years, the environmental cost of an electric car became roughly equivalent to that of a gasoline car.
However, all car batteries will now be reconnected together in huge containers, and they will be converted into batteries for energy storage. This will make the electric car more environmentally competitive than the gasoline car.
There are a lot of studies on this and you are right that it is not that obvious.