When I added a new module, ng build process just getting killed.
This is indeed a memory problem. If you can't add extra physical memory, you could create a swap file to add extra RAM memory.
// Create a swapfile
sudo fallocate -l 4G /swapfile
// Set up the swapspace
sudo mkswap /swapfile
// enable swapfile
sudo swapon /swapfile
The swapfile won't be recreated if you reboot. In case you want your swapfile to be permanent, edit the stab file with sudo nano fstab and add the following line to it:
/swapfile none swap sw 0 0
Linux will kill processes when it's low on memory which means your process is eating more memory than there is available. To regulate Node's memory usage you can use:
node --max_old_space_size=1096 ./node_modules/@angular/cli/bin/ng build --prod
where 1096 can be replaced by the memory you have left
Another solution is to add memory, or free it. This can be done by adding swap for example
I also face this problem on Linux Server. This is memory issue. Linux server is not enough for webpack's uglify plugin, So Adding extra memory space on the server solved the issue
For Centos 7
An addition to Kurt's answer.
Creating a swap file in Centos 7 won't work with the suggested commands.
The fallocate command does not work well in Centos 7 and creates the following error when calling swapon:
swapon: /swapfile: swapon failed: Invalid argument
Also you are advised to change permissions of file to 0600 before enabling swap file. So, eventually you can do the following:
sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
sudo mkswap /swapfile
sudo chmod 0600 /swapfile
sudo swapon /swapfile