To solve the error "ng: command not found", install the angular cli package globally by running npm install -g @angular/cli@latest and restart your terminal. If the command fails, run it with sudo and make sure the correct PATH is set in your system's environment variable.
reason: In the Angular 12 version, run ng build, and now the default is production mode. This is a welcome change because it reduces the chance of inadvertently deploying a development build to a production environment, which is much slower and much larger, making it feel like Angular is very slow.
ng serve. To get the application running, the ng serve command must execute within the [name-of-app] folder. Anywhere within the folder will do. The Angular CLI must recognize that it is within an environment generated with ng new .
Difference between ng serve and ng buildThe ng serve command is intentionally for fast, local and iterative developments and also for builds, watches and serves the application from a local CLI development server. The ng build command is intentionally for building the apps and deploying the build artifacts.
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=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
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.
In your project dist folder is own by root
Try to use sudo ng serve
instead of ng serve
.
Another solution
When there is having a large number of files watch not work in linux.There is a Limit at INotify Watches on Linux. So increasing the watches limit
//When live server not work in linux
sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl -p --system
ng serve //You can also do sudo **ng serve**
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With