The mergers of binary compact objects such as neutron stars and black holes are of central interest to several areas of astrophysics, including as the progenitors of gamma-ray bursts (GRBs), sources of high-frequency gravitational waves and likely production sites for heavy element nucleosynthesis via rapid neutron capture (the r-process). These heavy elements include some of great geophysical, biological and cultural importance, such as thorium, iodine, and gold. Here we present observations of the exceptionally bright gamma-ray burst GRB230307A. We show that GRB 230307A belongs to the class of long-duration gamma-ray bursts associated with compact object mergers, and contains a kilonova similar to AT2017gfo, associated with the gravitational-wave merger GW170817. We obtained James Webb Space Telescope mid-infrared (mid-IR) imaging and spectroscopy 29 & 61 days after the burst. The spectroscopy shows an emission line at 2.1 microns which we interpret as tellurium (atomic mass A=130), and a very red source, emitting most of its light in the mid-IR due to the production of lanthanides. These observations demonstrate that nucleosynthesis in GRBs can create r-process elements across a broad atomic mass range and play a central role in heavy element nucleosynthesis across the Universe.