Not fentanyl. Fentanyl precursors. That's a critical distinction.
China has an extremely large chemical industry. They supply the world's pharmaceutical industries for their re-agents, precursors and such.
Fentanyl, like LSD, is highly HIGHLY potent, so quantities of ingredients don't actually have to be so high so that it becomes obvious. Also like LSD, there's analogues up and down the chain. They've banned all analogues of fentanyl and some of the direct precursors, but analogues and other pathways exist and new ones are constantly invented to circumvent bans.
In hindsight, it would have been better to not have wrecked Latin America so much that there's sophisticated mega-cartels that overwhelm whole nations, but what can you do...