# Running out of memory when building docker image (npm)

**URL:** <https://community.fly.io/t/running-out-of-memory-when-building-docker-image-npm/21920>\
**Category:** Questions / Help\
**Tags:** nodejs, builders, login-only\
**Created:** [September 17, 2024, 11:51pm UTC](https://community.fly.io/t/running-out-of-memory-when-building-docker-image-npm/21920 "2024-09-17T23:51:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![leo-frdm](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@leo-frdm](https://community.fly.io/u/leo-frdm)\
**Post date:** [September 17, 2024, 11:51pm UTC](https://community.fly.io/t/running-out-of-memory-when-building-docker-image-npm/21920/1 "2024-09-17T23:51:35Z")

</div>

I’m working on a legacy app that has some node and some php.

I’m writing a Dockerfile more or less from scratch. It compiles locally as expected, and I can do fly deploy --local-only successfully. However, using the remote builder, I eventually get an out of memory when I reach the js bundling step (`rollup`):

```auto
1.300 > rollup -c
1.300 
2.142 
2.142 src/main.js → public/build/bundle.js...
55.63 
55.63 <--- Last few GCs --->
55.63 
55.63 [31:0x54b4160] 53038 ms: Mark-sweep (reduce) 1952.0 (1994.3) -> 1951.5 (1994.8) MB, 204.6 / 0.0 ms (+ 822.3 ms in 185 steps since start of marking, biggest step 7.3 ms, walltime since start of marking 1227 ms) (average mu = 0.600, current mu = 0.356) [31:0x54b4160] 54317 ms: Mark-sweep (reduce) 1952.7 (1994.8) -> 1952.2 (1995.3) MB, 1275.6 / 0.0 ms (average mu = 0.386, current mu = 0.003) allocation failure scavenge might not succeed
55.63 
55.63 
55.63 <--- JS stacktrace --->
55.63 
55.63 FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

```

When I run this locally, I can see it peaks at around 16GB of memory usage, so I guess that’s what I need to expect the remote builder be able to handle.

What are some reasonable ways to proceed here?

I want to keep using the remote builder, but I also don’t want (or need) one that permanently sits there with 16GB+ of memory. I tried looking for options of specifying swap for the remote builder but couldn’t find any (besides maybe manually dumping the builder fly.toml and adding swap\_size\_mb?

I took a look at [GitHub - fly-apps/dockerfile-node: Dockerfile generator for Node.js](https://github.com/fly-apps/dockerfile-node?tab=readme-ov-file) but it produces a Dockerfile more or less similar to what I already have, and I get the same error anyway.

Thoughts?

---

<div class="post-metadata">

**Author:** ![rubys](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/rubys/32/16907_2.png) [@rubys](https://community.fly.io/u/rubys)\
**Post date:** [September 18, 2024, 12:14am UTC](https://community.fly.io/t/running-out-of-memory-when-building-docker-image-npm/21920/2 "2024-09-18T00:14:07Z")

</div>

That seems unusual. Rollup shouldn’t need that much memory. Perhaps look into [`--max-old-space-size=SIZE`](https://nodejs.org/api/cli.html#--max-old-space-sizesize-in-megabytes)?

Also, try both `fly deploy --depot=false` and `fly deploy --depot=true`.

Finally, could this be of help: [rollup-plugin-esbuild - npm](https://www.npmjs.com/package/rollup-plugin-esbuild) ?

---

<div class="post-metadata">

**Author:** ![leo-frdm](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@leo-frdm](https://community.fly.io/u/leo-frdm)\
**Post date:** [September 18, 2024, 3:57pm UTC](https://community.fly.io/t/running-out-of-memory-when-building-docker-image-npm/21920/3 "2024-09-18T15:57:02Z")

</div>

Thanks, I forgot to mention I had already tried --max-old-space-size, got the same error.

However, when using that option **and** `--depot=false`, I got the deploy working!

For those searching in the future, this is what works for me: `node --max-old-space-size=16192 /usr/local/bin/rollup -c`.

---

<div class="post-metadata">

**Author:** ![pier](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/pier/32/74_2.png) [@pier](https://community.fly.io/u/pier)\
**Post date:** [September 18, 2024, 8:07pm UTC](https://community.fly.io/t/running-out-of-memory-when-building-docker-image-npm/21920/4 "2024-09-18T20:07:30Z")

</div>

Out of curiosity, what version of Rollup are you using?

---

<div class="post-metadata">

**Author:** ![leo-frdm](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@leo-frdm](https://community.fly.io/u/leo-frdm)\
**Post date:** [September 18, 2024, 8:24pm UTC](https://community.fly.io/t/running-out-of-memory-when-building-docker-image-npm/21920/5 "2024-09-18T20:24:41Z")

</div>

“rollup”: “^2.79.1”,

---

<div class="post-metadata">

**Author:** ![pier](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/pier/32/74_2.png) [@pier](https://community.fly.io/u/pier)\
**Post date:** [September 18, 2024, 11:14pm UTC](https://community.fly.io/t/running-out-of-memory-when-building-docker-image-npm/21920/6 "2024-09-18T23:14:20Z")

</div>

I seem to remember they fixed some memory issues in v3 but yeah if the project is big enough you will hit this eventually.

> **[Troubleshooting | Rollup](https://rollupjs.org/troubleshooting/#error-javascript-heap-out-of-memory)**
>
> The JavaScript module bundler

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [September 25, 2024, 11:14pm UTC](https://community.fly.io/t/running-out-of-memory-when-building-docker-image-npm/21920/7 "2024-09-25T23:14:46Z")

</div>

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