DEV Community

Mohammed Al-Sarraj
Mohammed Al-Sarraj

Posted on

πŸ›  Fixing Broken Angular Live Reload & EPERM Errors on Windows (For Good)

Hello DEV Community πŸ‘‹

If you develop Angular applications on Windows, you’ve probably faced at least one of these frustrating issues:

Live Reload randomly stops working β€” you save a file, but the browser doesn’t refresh.

The dreaded EPERM error β€” the .angular/cache directory gets locked and crashes your build.

These problems are usually caused by Windows file system behavior and file watcher limitations.

As a Full-Stack Engineer who values a smooth Developer Experience (DX), I got tired of manually deleting the cache and restarting the server.

So I built a lightweight automation script to handle it for me.

πŸ’‘ The Solution: Angular Auto Runner

A simple Batch script (Run-Project.bat) that you drop into your project root.

Double-click it β€” and your Angular environment is clean, verified, and running safely.

πŸ”Ž What the Script Does
🧹 1. Cleans Angular Cache

Force-deletes .angular/cache before launch to eliminate common EPERM lock issues.

πŸ“¦ 2. Verifies Dependencies

Checks if node_modules exists.
If missing (e.g., fresh clone), it automatically runs npm install.

⚑ 3. Forces Reliable Live Reload

Runs:

ng serve --hmr --poll 2000 --open

The --poll 2000 flag forces Angular to check file changes every 2 seconds β€” a reliable workaround for Windows file watcher instability.

πŸ’» The Script
@echo off
title Angular Auto Runner - Windows Fix
color 0A

echo ===================================================
echo Angular Ultimate Runner (Windows Fix)
echo ===================================================
echo.

:: 1. Clean Angular Cache
echo [1/3] Cleaning Angular Cache...
if exist ".angular\cache" (
rmdir /s /q ".angular\cache"
)

:: 2. Check Dependencies
echo [2/3] Checking dependencies...
if not exist "node_modules" (
echo [!] node_modules not found. Installing dependencies...
call npm install
)

:: 3. Launch Angular with Polling + HMR
echo [3/3] Launching Angular...
echo Mode: HMR + Polling (Windows Safe Mode)
echo ===================================================
call ng serve --hmr --poll 2000 --open

echo.
echo [!] Server stopped.
pause
πŸ“‚ Get the Script

You can grab the file and full documentation from my GitHub repository:

πŸ‘‰ Angular Auto Runner

If you're developing Angular on Windows, this might save you from a lot of unnecessary restarts and debugging headaches.

If you use a different approach or have other Windows-specific Angular fixes, I’d love to hear them in the comments.

Happy coding πŸš€

Top comments (0)