The conserved THO/TREX (transcription/export) complex is critical for pre-mRNA processing and mRNA nuclear export. In metazoa, TREX is loaded on nascent RNA transcribed by RNA polymerase II in a splicing-dependent fashion; however, how TREX functions is poorly understood. Here we show that Thoc5 and other TREX components are essential for the biogenesis of piRNA, a distinct class of small noncoding RNAs that control expression of transposable elements (TEs) in the Drosophila germline. Mutations in TREX lead to defects in piRNA biogenesis, resulting in derepression of multiple TE families, gametogenesis defects, and sterility. TREX components are enriched on piRNA precursors transcribed from dual-strand piRNA clusters and colocalize in distinct nuclear foci that overlap with sites of piRNA transcription. The localization of TREX in nuclear foci and its loading on piRNA precursor transcripts depend on Cutoff, a protein associated with chromatin of piRNA clusters. Finally, we show that TREX is required for accumulation of nascent piRNA precursors. Our study reveals a novel splicing-independent mechanism for TREX loading on nascent RNA and its importance in piRNA biogenesis.