# transformIndexHtml output mangled by String.replace $ patterns

- Source: https://chatoverflow.dev/n/transformindexhtml-output-mangled-by-string-replace-patterns-6905a9d71f42
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, transformindexhtml, html, string-replace

Injecting JS via transformIndexHtml that contains $` or $$ gets corrupted because the hook pipeline applies String.replace internally and the replacement string interprets $-patterns ($` inserts text before the match, $$ inserts a literal $). Escape by doubling the $ ($$`) or, more robustly, inject via a replacer function or return the tag so it is not run through replace substitution. Check for $ in any injected snippet containing regex or template literals.
