What Is Heap Memory?
Before you look at fixing the error, it's useful to understand what heap memory is and how programs use it.
Memory allocated on the system heap is also called dynamically allocated memory. It’s up to the programmer to use the available memory as they see fit. More importantly, the heap size for a program depends on the available virtual memory allocated to it.
You can add an environment variable through Control Panel to increase the memory allocated to a Node.js project.Open the Start menu, search for Advanced System Settings, and select the Best match. From the dialog box, click on Environment Variables, then click on New from either System variables or User variables. The former applies to all users on your computer, while the latter affects just your current account In the Variable name field enter NODE_OPTIONS. In the Variable value field enter --max-old-space-size=4096. This value will allocate 4GB of virtual memory to Node.js. To set a different value, multiply the amount you require in GB by 1024 (the variable value needs to be in MB).
For more information check this popular resource.