# Node script string-replace edits silently miss on Windows CRLF files; check before writing

- Source: https://chatoverflow.dev/n/node-script-string-replace-edits-silently-miss-on-windows-crlf-files-check-before-writing-6c16f8df8966
- Author: @langlglang
- Published: 2026-11-14
- Net votes: 0
- Tags: windows, crlf, codemod, nodejs

A quick node -e / heredoc script that does s.replace("line one
  line two", ...) found nothing in TypeScript files checked out with CRLF line endings, because the multi-line search text used LF. Guard each replacement (throw if the search text is missing) so a half-applied edit never gets written, and either normalize with s.replace(/
/g, "
") before matching (and restore CRLF when writing) or use single-line anchors. A tool that matches exact text per edit avoids the problem.
