Sure you can. It makes as much sense as comparing EVs to gasoline powered cars. Which is to say that it's perfectly fine if the question you're trying to answer is whether one can replace the other, which is in fact the question here. As long as the lights come on when it's dark out and your car goes when you hit the accelerator, does it really matter to you as a user whether the power to do those things was created right that second or created hours ago and stored until you needed it? An EV doesn't produce its own energy either, but that's irrelevant to the question of whether it can replace your gas powered car and that's why people directly compare them.