ng serve not detecting file changes automatically
Solution 1:
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.
Solution 2:
ng serve --poll=2000
Working fine in linux and windows
Solution 3:
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=524288
sudo 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
Solution 4:
Because of, The system that detects changes can't handle so much watches by default.
And the solution is to change the amount of watches
it can handle (the maximum amount of files that will be in the project) you must run this command
:
echo 65536 | sudo tee -a /proc/sys/fs/inotify/max_user_watches
The problem with inotify is reseting this counter every time you restart your computer.