TypeError: duplicated codec.preferredPayloadType

Confirmed The error duplicated codec.preferredPayloadType was being caused by too many elements in the array returned by getSupportedRtpCapabilities(). Thanks for that tip!

This works; it just removes some of the most repeated codecs which are not that interesting for WebRTC usage with current web browsers:

worker.createRouter({
  mediaCodecs: Mediasoup.getSupportedRtpCapabilities()
    .codecs?.filter(
      (c) =>
        c.mimeType !== "audio/SILK" &&
        c.mimeType !== "audio/CN" &&
        c.mimeType !== "audio/telephone-event"
    )
    .map((c) => {
      delete c.preferredPayloadType;
      return c;
    }),
});