# Node Docker Image max\_old\_space\_size

**URL:** <https://discuss.circleci.com/t/node-docker-image-max-old-space-size/31868>\
**Category:** Build Environment\
**Tags:** nodejs\
**Created:** [August 12, 2019, 1:41pm UTC](https://discuss.circleci.com/t/node-docker-image-max-old-space-size/31868 "2019-08-12T13:41:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![valentim](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@valentim](https://discuss.circleci.com/u/valentim)\
**Post date:** [August 12, 2019, 1:41pm UTC](https://discuss.circleci.com/t/node-docker-image-max-old-space-size/31868/1 "2019-08-12T13:41:53Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![fernfernfern](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/fernfernfern/32/8596_2.png) [@fernfernfern](https://discuss.circleci.com/u/fernfernfern)\
**Post date:** [August 12, 2019, 1:54pm UTC](https://discuss.circleci.com/t/node-docker-image-max-old-space-size/31868/2 "2019-08-12T13:54:38Z")

</div>

You may want to try using `NODE_OPTIONS`. Is `TOOL_NODE_FLAGS` specific to meteor? If i’m reading things on the interwebs correctly it seems like it might be. `NODE_OPTIONS` should pass it directly to node. You can refer to [https://support.circleci.com/hc/en-us/articles/360009208393-How-can-I-increase-the-max-memory-for-Node-](https://support.circleci.com/hc/en-us/articles/360009208393-How-can-I-increase-the-max-memory-for-Node-)

---

<div class="post-metadata">

**Author:** ![valentim](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@valentim](https://discuss.circleci.com/u/valentim)\
**Post date:** [August 12, 2019, 2:03pm UTC](https://discuss.circleci.com/t/node-docker-image-max-old-space-size/31868/3 "2019-08-12T14:03:38Z")

</div>

Thank you! It looks like this approach has worked. Will do additional testing and report back with more detail.

> **[How can I increase the max memory for Node?](https://support.circleci.com/hc/en-us/articles/360009208393-How-can-I-increase-the-max-memory-for-Node-)**
>
> Node has a default max memory usage of less than 2GB on some 64bit systems. This can cause unexpected memory issues when running on CircleCI. It's possible to adjust the max memory ceiling using:
> \-...

---

<div class="post-metadata">

**Author:** ![valentim](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@valentim](https://discuss.circleci.com/u/valentim)\
**Post date:** [August 12, 2019, 5:21pm UTC](https://discuss.circleci.com/t/node-docker-image-max-old-space-size/31868/4 "2019-08-12T17:21:03Z")

</div>

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:

```

[https://circleci.com/docs/2.0/configuration-reference/#jobs](https://circleci.com/docs/2.0/configuration-reference/#jobs)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [August 22, 2019, 5:21pm UTC](https://discuss.circleci.com/t/node-docker-image-max-old-space-size/31868/5 "2019-08-22T17:21:03Z")

</div>

Closed on August 22, 2019, 5:21pm UTC

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
