'Nx lib when imported into Angular project takes too long to compile and run and eats up entire allocated Node's memory

I have an Angular project in Nx workspace, have used ng-openapi-gen to created API client from loopback to be used by my Angular project. I created an Angular lib on the workspace where I have placed the generated API client to be used in a library-way.

Now the process breaks saying maximum heap size reached, its using more than 8GB of node's memory(tried increasing the node memory to make it work but failed).

I want to optimize it if possible and want to know about any debugger to exactly know which part of the library is taking up the entire space?

Initially using ng-openapi-gen when it created my services to be used in my applications, I commented all the services and only allowed a couple of them to be used. It worked fine and also compiled in limited time and space and also re-compilation was fast on any incremental change in the Angular application.

On uncommenting all the services and then trying it out the problem of memory and time appears again.

I am sure that things would work if there were less services but I want to make it work with how many ever services I want the project to have.

Exactly what I am doing is demonstrated in this video:
https://www.youtube.com/watch?v=wtIVxvJFT2k&list=LL&index=6&t=1972s



Sources

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

Source: Stack Overflow

Solution Source