Worker failing with the error “JavaScript heap memory full.”

Hi, I'm facing a problem with my Cloudflare Worker building process: my NuxtJS build has recently been failing with a “JavaScript heap memory full” error. Everything looks fine at first, but during prerendering, when resvg is supposed to generate the OG images, I get an out-of-memory error:
02:54:29.854 [info] [nitro] Building Nuxt Nitro server (preset: `cloudflare-module`, compatibility date: `2025-07-16`)
02:54:59.940 [plugin inject] node_modules/.pnpm/@resvg+resvg-wasm@2.6.2/node_modules/@resvg/resvg-wasm/ index_bg.wasm?module: rollup-plugin-inject: failed to parse /opt/buildhome/repo/node_modules/.pnpm/@resvg+resvg-wasm@2.6.2/node_modules/@resvg/resvg-wasm/index_bg.wasm?module. Consider restricting the plugin to particular files via options.include

02:55:20.480
02:55:20.480 <--- Last few GCs --->
02:55:20.480
02:55:20.480 [1148:0xfd94000] 96816 ms: Mark-Compact 2035.2 (2087.8) -> 2032.9 (2087.8) MB, pooled: 0 MB, 700.69 / 0.00 ms (average mu = 0.236, current mu = 0.139) allocation failure; GC in old space requested
02:55:20.481 [1148:0xfd94000] 98000 ms: Mark-Compact 2033.4 (2087.8) -> 2033.3 (2092.0) MB, pooled: 0 MB, 1085.01 / 0.00 ms (average mu = 0.153, current mu = 0.084) allocation failure; GC in old space requested
02:54:29.854 [info] [nitro] Building Nuxt Nitro server (preset: `cloudflare-module`, compatibility date: `2025-07-16`)
02:54:59.940 [plugin inject] node_modules/.pnpm/@resvg+resvg-wasm@2.6.2/node_modules/@resvg/resvg-wasm/ index_bg.wasm?module: rollup-plugin-inject: failed to parse /opt/buildhome/repo/node_modules/.pnpm/@resvg+resvg-wasm@2.6.2/node_modules/@resvg/resvg-wasm/index_bg.wasm?module. Consider restricting the plugin to particular files via options.include

02:55:20.480
02:55:20.480 <--- Last few GCs --->
02:55:20.480
02:55:20.480 [1148:0xfd94000] 96816 ms: Mark-Compact 2035.2 (2087.8) -> 2032.9 (2087.8) MB, pooled: 0 MB, 700.69 / 0.00 ms (average mu = 0.236, current mu = 0.139) allocation failure; GC in old space requested
02:55:20.481 [1148:0xfd94000] 98000 ms: Mark-Compact 2033.4 (2087.8) -> 2033.3 (2092.0) MB, pooled: 0 MB, 1085.01 / 0.00 ms (average mu = 0.153, current mu = 0.084) allocation failure; GC in old space requested
I have attached the complete build log and my nuxt.config.ts. Does anyone know anything more about this? Thanks, Thomas 🙂
2 Replies
kian
kian2w ago
Sometimes with a big enough project you just have to increase the amount of memory given to Node Take a look at the --max-old-space-size Node option
cappy989
cappy989OP2w ago
Thanks! This solved the problem 🙂

Did you find this page helpful?