1

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!

Khodor Khalil
  • 49
  • 1
  • 5

1 Answers1

0

Sorry to answer it after such a long time and I just met the same problem after adding some dependencies to the angular project. I post it here in case anyone need it. No official way found to fix it but I found that if you add "optimization": false to the angular.json file. Then everything works. I think there's something wrong in the process of optimization(minimize the scripts .etc). The code block like the following:

"configurations": {
    "production": {
      "optimization": false,
      "budgets": [
        {
          "type": "initial",
          "maximumWarning": "30mb",
          "maximumError": "50mb"
        },
        {
          "type": "anyComponentStyle",
          "maximumWarning": "2mb",
          "maximumError": "4mb"
        }
      ],
      "fileReplacements": [
        {
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.prod.ts"
        }
      ],
      "outputHashing": "all"
    }
}