Carbon dioxide (CO2) is one of the most abundant ices in the solar system. It has been detected in giant planet atmospheres and on their moons, on and around comets, and even in regions of Mercury, the Moon, and Mars. However, despite their formation in the coldest regions of the protoplanetary disk, CO2 was not previously detected on trans-Neptunian objects (TNOs). Carbon monoxide (CO) was only expected to be present in the largest TNOs. Out of 45 total, we report the detection of both CO2 and CO in 42 and 24 TNOs, respectively, observed with the NIRSpec instrument on the JWST by the DiSCo-TNOs project (PID 2418). Our analysis shows that \diox is widespread in the trans-Neptunian region, independent of dynamical class, while CO is a common constituent of the reddest objects in our sample. The abundance and characteristics of \diox suggest that most of it could be primordially accreted. While, CO is probably being produced by ion irradiation of CO2 and other C-bearing species. Our results suggest the prevalence of two compositional groups among TNOs based on the abundance and properties of CO2 and CO. We discuss the implication of these results in the context of solar system formation.