Running out of memory when building docker image (npm)

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):

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 but it produces a Dockerfile more or less similar to what I already have, and I get the same error anyway.

Thoughts?

That seems unusual. Rollup shouldn’t need that much memory. Perhaps look into --max-old-space-size=SIZE?

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

Finally, could this be of help: rollup-plugin-esbuild - npm ?

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.

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

“rollup”: “^2.79.1”,

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

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