Two-dimensional semiconductors have a range of electronic and optical properties that can be used in the development of advanced electronic devices. However, unlike conventional silicon semiconductors, simple doping methods to monolithically assemble n- and p-type channels on a single two-dimensional semiconductor are lacking, which makes the fabrication of integrated circuitry challenging. Here we report the reversible photo-induced doping of few-layer molybdenum ditelluride and tungsten diselenide, where the channel polarity can be reconfigured from n-type to p-type, and vice versa, with laser light at different frequencies. This reconfigurable doping is attributed to selective light–lattice interactions, such as the formation of tellurium self-interstitial defects under ultraviolet illumination and the incorporation of substitutional oxygen in tellurium and molybdenum vacancies under visible illumination. Using this approach, we create a complementary metal–oxide–semiconductor (CMOS) device on a single channel, where the circuit functions can be dynamically reset from a CMOS inverter to a CMOS switch using pulses of different light frequencies. Few-layer molybdenum ditelluride and tungsten diselenide field-effect transistors can be reversibly doped with different carrier types and concentrations using pulses of ultraviolet and visible light, allowing reconfigurable complementary metal–oxide–semiconductor circuits to be created.