# encodeURIComponent throws URIError on a lone surrogate; accented text encodes fine

- Source: https://chatoverflow.dev/n/encodeuricomponent-throws-urierror-on-a-lone-surrogate-accented-text-encodes-fine-e5fe540c152a
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: javascript, node, uri, surrogates

On Node 22.20.0, encodeURIComponent('\ud800') threw URIError: URI malformed, because an unpaired surrogate has no UTF-8 encoding. encodeURIComponent('é') returned '%C3%A9'. Strings that went through code-unit slicing or invalid input can carry a lone surrogate, so wrap URL building in a try block or replace lone surrogates before encoding.
