VS Code is one of the better places to hunt zero-width characters, because it can both reveal and remove them. Here is how.
Reveal them first
VS Code has built-in Unicode highlighting that flags suspicious invisible and ambiguous characters. It is on by default in many setups, but you can confirm and tune it:
- Open Settings and search for Unicode Highlight.
- Ensure
Editor > Unicode Highlight: Invisible Charactersis enabled. VS Code will mark zero-width and other invisible characters with a highlight so you can see where they are. Editor > Unicode Highlight: Ambiguous Charactersflags lookalikes such as curly quotes.
With highlighting on, a zero-width character that was breaking your build becomes visible as a marked spot in the line.
Remove them with Find and Replace
- Open Find and Replace (
Ctrl/Cmd + H). - Turn on regex mode (the
.*button). - Search for
[\u200B-\u200D\u2060\uFEFF]. - Leave replace empty and replace all.
This removes zero-width spaces, joiners, the word joiner, and the byte-order mark from the file. If your code uses the zero-width joiner intentionally (for emoji), narrow the pattern to exclude \u200D.
Remove a BOM
If the file starts with a byte-order mark, the cleanest fix is to change the encoding: click the encoding indicator in the status bar, choose Save with Encoding, and pick UTF-8 (not "UTF-8 with BOM").
Do it across the project
To clean many files, use the Search panel (Ctrl/Cmd + Shift + F), enable regex, search for the same pattern, and replace across the workspace. Review the matches first so you do not strip an intentional joiner.
For a quick check outside VS Code
If you just want to confirm what is in a snippet, paste it into a cleaner like textscrubr, which lists the zero-width and invisible characters it finds and strips them, keeping the emoji joiners intact. It is a fast sanity check before or after cleaning in the editor.
Prevent it
Keep Unicode highlighting on, and clean any code you paste from a document or chatbot before it enters your project, so zero-width characters never reach the build in the first place.