A gasoline/diesel engine will just seize up when exposed to water, and if it's on fire it will be extinguished. Same for electric motors.
Batteries however? No bueno. Both the Americans [1] and Russians [2] lost submarines to battery fires. Batteries are hard and marine environments are among the nastiest you can get with corrosive saltwater and mist everywhere and continuous extreme mechanical shock events from waves and storms.
This is also why I believe that it's a fools errand to waste any non-fossil fuel (no matter if "sustainable" production from grains, frying oil or similar, or synth-fuels) on heating homes like it has been proposed in Germany or driving cars with it. The stuff is far too valuable, we'll need it for a long time to power aviation and maritime navigation until we get batteries both high-capacity and safe enough for these cases.
[1] https://en.wikipedia.org/wiki/USS_Bonefish_(SS-582)
[2]https://www.theguardian.com/world/2019/jul/23/russia-submers...
Nowadays, even small yachts are becoming hybrid or pure electric. My friend's 37ft sailing monohull is pure electric, so is my 35ft sailing catamaran.
Many folks have a generator in case they need more range and there isn't enough wind. But I personally haven't needed it yet, but I also don't sail long distances. I would probably bring a generator if I did, in case there's no wind and I need to move.
My friend has a generator aboard but hasn't used it once yet, and he made it to Puerto Vallarta from SF.
If you do an image search for "marina" you can even spot them on most stock photos.
Range is not really a problem if you plan carefully and are patient. I try not to motor much anyway -- it being a sailboat and all. I do have a back up generator though.