ng serve not detecting file changes automatically ng serve not detecting file changes automatically angular angular

ng serve not detecting file changes automatically


Most of the times in Linux, ng serve or ng build --watch doesn't work if the directory doesn't have sufficient permissions.

The solution is either to provide the necessary permissions or to use sudo instead.

UPDATE

watch flag in ng serve is actually redundant as it is the default option. Credit to @Zaphoid for pointing out the mistake.


ng serve --poll=2000

Working fine in linux and windows


Consider that, when having a large number of files, there is a Limit at INotify Watches on Linux. So increasing the watches limit to 512K, for example, can solve this.

sudo sysctl fs.inotify.max_user_watches=524288sudo sysctl -p --system

Note that the previous causes an in-memory change that you will lose after restart.

However, you can make it persistent, by executing:

echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system

As a reference, you can check: https://github.com/angular/angular-cli/issues/8313#issuecomment-362728855 and https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers