Diodes based on p−n junctions are fundamental building blocks for numerous circuits, including rectifiers, photovoltaic cells, light-emitting diodes (LEDs), and photodetectors. However, conventional doping techniques to form por n-type semiconductors introduce impurities that lead to Coulomb scattering. When it comes to low-dimensional materials, controllable and stable doping is challenging due to the feature of atomic thickness. Here, by selectively depositing dielectric layers of Y 2 O 3 and AlN, direct formation of waferscale carbon-nanotube (CNT) diodes are demonstrated with high yield and spatial controllability. It is found that the oxygen interstitials in Y 2 O 3 , and the oxygen vacancy together with Al− Al bond in AlN/Y 2 O 3 electrostatically modulate the intrinsic CNTs channel, which leads to p-and n-type conductance, respectively. These CNTs diodes exhibit a high rectification ratio (>10 4 ) and gate-tunable rectification behavior. Based on these results, we demonstrate the applicability of the diodes in electrostatic discharge (ESD) protection and photodetection.