'Build process is taking 2GB of ram and it fails

When I run npm run build command on the server, I am getting this error and the process fails:

Error : the build failed because the process exited too early. this probably means the system ran out of memory or someone called kill -9 on the process

Statistics while the build process:

enter image description here

It's a 2 GB server, I want to know that why build process is taking 2 GB of RAM? any solution regarding how to reduce it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source