Fixing Delete CR Prettier Error
The “Delete CR” error appears when your files use Windows-style line endings (CRLF) while Prettier expects Unix-style line endings (LF). This commonly happens in cross‑platform projects or when using tools like WSL, Docker, or remote editors.
Why the Error Happens
- Windows uses CRLF
- macOS/Linux use LF
- Prettier prefers LF
- If a file contains CRLF, ESLint shows:
Delete 'CR' [prettier/prettier]
This mismatch leads to formatting conflicts that break CI, linting, or pre‑commit checks.
1. Fix ESLint + Prettier Config (Recommended)
.prettierrc
{
"endOfLine": "auto"
}.eslintrc.js
module.exports = {
rules: {
"prettier/prettier": ["error", { endOfLine: "auto" }]
}
};This allows Prettier to accept LF/CRLF dynamically.
2. Convert Line Endings Using VS Code
- Open a file
- Bottom‑right corner → click CRLF
- Switch to LF
- Press Ctrl+Shift+P → Change All End of Line Sequence
3. Fix Line Endings Through Git
Add:
.gitattributes
* text=auto eol=lfRe‑normalize repository:
git rm --cached -r .
git reset --hard4. Convert Files in Terminal
Convert CRLF → LF
dos2unix file.jsConvert LF → CRLF
unix2dos file.jsInstall via:
sudo apt install dos2unix5. Prettier 3.x Modern Config
For new Prettier versions:
prettier.config.js
export default {
endOfLine: "auto"
};6. WSL, Docker, and Remote Environments
VS Code (WSL)
"files.eol": "\n"Git inside Docker
git config core.autocrlf false7. Use Pre‑commit Hooks to Enforce LF
Install:
npm i -D husky lint-stagedAdd:
"lint-staged": {
"*": ["prettier --write"]
}This ensures consistent formatting before each commit.
Conclusion
This ESLint/Prettier error is simply a line‑ending mismatch. By configuring Prettier, ESLint, Git, your editor, and using pre‑commit hooks, you can eliminate the issue permanently and avoid cross‑platform inconsistencies.