I'm working on an old Angular project with a lot of NPM dependancies (we started with an angular 2 beta ^^ several years ago), we just migrated to Angular 9. Since a couple of weeks, the ng build command fails randomly on our CI, because of a memory issue:
92% chunk asset optimization TerserPluginAn unhandled exception occurred: spawn ENOMEM
Thing is, we already allocated 16Gb of RAM to the project and it's not enough, we tried also to adjust the max_old_space_size parameter, but now we are at the maximum of the memory allocation and no swap option available.
I would like to understand why the ng build command needs so many memory, but I can't find a way to debug the build process to find the issue. I know it's probably related to some package but I have no idea how to identify it...
Do you know what are the best practices to avoid consuming too much memory at build? how can I debug or inspect the "npm run build" command to find the issue?
Many thanks in advance for your help!