And, North Korea didn't have oil. If the US just wanted to invade a country to make the world a better place then there would have been plenty of easier countries to invade. How about Zimbabwe or Eritrea to mention just a few.
North Korea is China's laboratory for orthodox communism. They need it to remind party faithfuls what it would mean to return to the iron rice bowl (which sometimes lacks both rice and iron). Having some 25 million people occasionally suffer from hunger is preferable to losing stability in a country of 1400 million.
North Korea would collapse very quickly without China's support in fuels and food.
Speaking in absolutes ("If China wanted them to not have nukes, they wouldn't have") is usually a mistake in geopolitics.
China currently won't accept a unified Korea under South Korean rule (which they view as a US proxy). China also doesn't want a destabilized North Korea on its border. But it is likely that many outside China and the Koreas view China's influence as a lot more than it is.
China had Kim Jong Un half-brother under their protection as a way of providing a credible threat of threatening regime change. That isn't an option anymore.
I'd note this quote from a well-sourced FT article from last year:
Beijing has often talked up its influence over its recalcitrant neighbour in its discussions with Washington, but when Pyongyang claimed to have tested a hydrogen bomb this year, Beijing had no idea it was coming, according to several people with knowledge of the matter.
and this:
It may seem ludicrous to outsiders, but several close observers of North Korea told the FT that, given the choice, Mr Kim would prefer an alliance with America, the far-off superpower, than China, the ancient oppressor and emerging superpower.
We have a similar view on NK's raison d'etre. I think neither China nor SK want to be neighbors, and NK makes for a perfect buffer state, with the exception of the nuclear (and other WMDs, hypothetically) wrinkle.