Firstly, I don't agree that China should escalate to a nuclear war even if China attempted to invade Taiwan ended up in a failure. China has a no first use policy for nuke and I do believe China would stick to this policy.
Secondly, if the Western powers intervened in the war, then a nuclear exchange would never be ruled out. China is a nuclear power. It is building up its nuclear arsenal. When countries with nukes fighting each others, nothing is going to be ruled out.
Thirdly, you assumed that the Western powers intervention would prevail. That's your opinion. Many people don't agree with you. So don't project your own thinking to other posters.
Fourthly, a member said that China should use nukes when the invasion failed. That's his opinion. I don't agree. However, I would point out China war doctrine is different than the West. China no first use policy has made that the use of nuke almost impossible for the military high command. Therefore, the military high command has developed a new war doctrine. That's China has a ballistic arsenal that can bring destruction to the enemies even greater scale through simply firing a few ballistic missiles pack with multiple tons of explosive to create the kinds of destruction that rival and exceed nukes.
Lastly, the war of reunification was the up most important to the CPC and the Chinese military and mainland Chinese. If the Western powers think that they could provoke China and induce Taiwan independent and get away with it. Then I would advise the West to seriously think the consequence and the fallout of a total war.
There's no need to go nuclear.
Even without an invasion attempt, remember that Taiwan will face collapse anyway due to the destruction of its industrial infrastructure and civilian economy.
From the civilian perspective, the electricity and fuel networks on Taiwan will be attacked. There are only 100-odd major targets like Power stations, Fuel Depots and Refineries. The transportation network could also be crippled with another 300-odd bridges on major rivers/canals in Taiwan, which would result in roughly 15 isolated regions comprising 1-2 million people each. I would see this happening within the first week, even with US intervention.
If these targets are hit, no matter what happens afterwards, it is only a matter of days/weeks before a societal collapse in Taiwan, reminiscent of the last days of Imperial Japan. Taiwan only produces one-third of its food requirements during peacetime and China can still prevent outside aircraft and ships from reaching Taiwan for example. I don't see any way for Taiwan to avoid this scenario except with a political settlement with China.