Our Angular 7 app has grown and our CircleCI build job is now erroring with:
“FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory”
We’ve upgraded our CircleCI plan and are using: resource_class: large (4 vCPUs 8 RAM)
My understanding is we need to increase the nodejs memory limit. However, it’s unclear what command/syntax we need in our config.yml to accomplish this. This is the relevant part of our config.yaml – but deploys are failing with the same error.
docker:
- image: circleci/node:9.9-browsers
environment:
TOOL_NODE_FLAGS: --max_old_space_size=4096
resource_class: large
Success! Deployments are now successfully building our Angular 7 app. Here’s a summary of the problem/resolution:
Building Angular apps can consume significant memory i.e. > 4GB.
CircleCI default docker images have a max of 4GB.
We upgraded our CircleCI plan to “Performance”.
Upgrading the plan allowed us to increase the size of the docker image. We’re currently using resource_class large (4 vCPUs 8 RAM)… Resource classes are well documented (see link below).
The NodeJS default memory limit is low so we also need to configure NodeJS to use more RAM. We chose to increase to 4GB based on Angular posts.
The support article above “How can I increase the max memory for Node” explains how to do this. However, it wasn’t clear after reading it a dozen times exactly “how”.
Add an environment variable “NODE_OPTIONS” with value “–max_old_space_size=4096” in the CircleCI website app (not in config.yaml). Jobs > Settings (gear icon) > Environment Variables > Add Variable.
Unknown if it’s possible to set max_old_space_size in config.yaml. But this would be a much better approach for us because we have many docker images in our config.yaml and we’re forced to bump them all up to resource_class large.
Here’s our final config.yaml snippet:
deploy-production:
working_directory: ~/tmp
docker:
- image: circleci/node:9.9
resource_class: large
steps: