Let's take that at face value "Ukraine becoming a NATO member". How does a war stop them from becoming a NATO member? Russia can not occupy Ukraine - they don't have the manpower for that.
What's the end game? What's the goals of the war? How does an invasion, that has to end at some point, stop Ukraine from joining NATO?
Even if Ukraine looses, Russia has no ability to force them to do anything. Russia wins - and then what?
Easiest way, you make them sign an agreement during peace negotiations. Maybe even just demonstrating that you are serious and what the consequences are might act as a deterant for at least some time. Install a pro Russian government.
You are right, nothing will guarantee that they never become a NATO member, but for some time is a plausible goal. Even just being in an active conflict prevents a NATO membership unless the rules are changed which is what Crimea and eastern Ukraine achieved since 2014.
What's the end game? What's the goals of the war? How does an invasion, that has to end at some point, stop Ukraine from joining NATO?
Even if Ukraine looses, Russia has no ability to force them to do anything. Russia wins - and then what?