What causes a 'URIError: URI malformed' error when using `decodeURIComponent` in a Webpack build?

Question

Grade: Education Subject: Support
What causes a 'URIError: URI malformed' error when using `decodeURIComponent` in a Webpack build?
Asked by:
97 Viewed 97 Answers

Answer (97)

Best Answer
(528)
This error typically occurs when `decodeURIComponent` is called on a string that isn't a valid URI component. This can happen if the string contains characters that are not properly encoded, or if it contains sequences that are invalid in a URI. In a Webpack context, this often arises from dynamic imports or code splitting where URLs are constructed or modified during the build process, potentially introducing invalid characters. Common culprits include spaces, control characters, or incorrectly encoded special characters.