Lithium-doping inverts the nanoscale electric field at the grain boundaries in Cu2ZnSn(S,Se)4 and increases photovoltaic efficiency.