We use time-dependent quantum wavepacket methods to simulate ballistic electron transport in a single-walled carbon nanotube field-effect transistor at terahertz frequencies ( approximately 100 GHz-10 THz). We observe an electron resonance phenomenon in a sub-picosecond-scale time domain. Our simulation results clearly show that the electron resonance corresponds to the formation of the resonance cavity and the interference of the electron wavepackets, which is directly supported by recent experimental measurements (Zhong et al 2008 Nat. Nanotechnol. 3 201).