Build Failed: build exceeded memory limit and was terminated

Hi Cloudflare Community,

My company has been deploying our react frontend for the past two years via Cloudflare pages. All day yesterday and today, all of a sudden, our builds fail with Failed: build exceeded memory limit and was terminated
There was no major infastructure changes in this release. We are using node version 14.21.3

Do you have any feedback on why this would be happening?  It builds fine locally.
1 Like

Can you please provide a deployment ID for one of the failed builds?

Thanks for the response.

Assuming that the deployment id can be taken from the URL,

Here are few that failed:
ac7e974c-9359-41ae-bbf0-ff7b467c2af4
fcd53484-eb7d-480f-8b7b-29063cff2ab7
86510e51-d624-4985-ae3b-401722ca6cdd

1 Like

We’re experiencing the same problem with many of our latest builds for the last two days:

  • 98286701-6f43-4cca-acbe-6ec2a72eb107
  • fcb358b8-fe90-4cdd-9334-0da2b30fdf9b
  • b46c6e40-f989-4f6b-b7d4-37b55d31fc67
  • 88a41268-acfb-47e7-b1fb-26f18696f847
  • 3040b0d7-6ecc-4d96-a146-419e0ab1c6bf

The first instance of our failing builds happened on 2024-01-08T21:16:36.135529Z. We haven’t had a successful build since.

that timeline matches up with what we’re experiencing

1 Like

Thank you. We recently upgraded our infrastructure which gives builds significantly increased disk IO. It looks like a small number of projects are consuming more memory as a result.

Here are some things that may help:

  • Reduce concurrency settings in your build (if applicable.) Eg. next.js defaults to 7 threads that can be overridden by specifying experimental.cpus: 4.
  • Reduce Node memory by specifying an environment variable: NODE_OPTIONS=--max-old-space-size=3072 (if you’re setting this elsewhere already, then change it there instead.)

I know this is frustrating and appreciate your patience.

Thanks for the response. However, that doesn’t seem to have fixed the issue.

I added Variable Name: NODE_MODULES and Value: --max-old-space-size=3072 to my preview environmental variables. I re-deployed a feature branch and got the same error.

I then edited the package.json from react-scripts build to node --max-old-space-size=3072 node_modules/.bin/react-scripts build with the same result.

Here are those 2 deployments:
614a5d2b-4fcc-4c12-91ec-afc4129a84a2
c1c5ce10-6765-4d3f-a7b3-f6ee8b7ddd2f

Hey @jhands1

Wanted to give some more feedback:

  • I am not aware of any concurrecny setting using react-scripts. This appears to be for next.js and therefore have not experimented with experimental.cpus
  • I’ve tried using environmental variables with the titles NODE_MODULES per your previous comment and NODE_OPTIONS from some other references. Both resulted in the same memory error with values of --max-old-space-size=3072
  • Our build command also included sentry source mapping. I’ve removed this thinking that it could be taking up too much memory, but still get the same memory error.
  • I tried dropping the max memory from 3072 to 2048. Locally, 2048MB is sufficient to build this project but still get the same error on cloudflare builds.

Do you have other suggestions to get this thing built? Many thanks! Jacob

I was able to get this to build. But it’s really odd, because I could only do it with BOTH of these env vars. Using just one would not work
NODE_MODULES=--max-old-space-size=2048
NODE_OPTIONS=--max-old-space-size=2048

Apologies @jacob25 - I meant NODE_OPTIONS, not NODE_MODULES. Great catch there. I updated my previous reply for clarity.

@colin.hoernig can you give your builds another try? I’ve opted you out of the infrastructure upgrade.

1 Like

Looks like builds started succeeding corresponding with you opting us out of the infrastructure change. Thank you!

hi @jhands1 @jfawcett

After working Wed and Thursday, all of our builds this morning are failing with the same memory error in this title.
I’ve tried to systematically increase the NODE_OPTIONS=--max-old-space-size=2048 to NODE_OPTIONS=--max-old-space-size=8192 all with the same result.

We did get a message at 8192 that memory usage was capped at 76XX MB.

Is there a way to resolve this issue? Revert to the infrastructure like you did with colin? We can adjust our cloudflare plan to get more memory as well. We just want these builds to start working again. Thanks!

Examples of failures:
1629f2d5-b929-4d2c-99da-cfae2156d98b
b67903b7-1ccb-4155-9e9b-baef18f070ae
6b878eac-7ac5-4bd9-baab-16d371e2e48f
8aaa8752-5846-48f0-bf74-2a5833ce5245

Hey there @jacob25 I’ve gone ahead and opted you out. Could your build again?

Yes, that worked!!!

Thanks so much for your help @jfawcett

@jfawcett Hello, I also encountered this problem in my project. Can you also help me exit the infrastructure upgrade? This is the deployment id: b239e565-2e26-459b-ae3f-9e1fff07b184

hi @jfawcett @jfawcett
My project started last week and the same build failed with the same memory error as this title.
I also tried increasing all NODE_OPTIONS=–max-old-space-size=2048 and NODE_OPTIONS=–max-old-space-size=8192 with the same result.
Is there a way to solve this problem? Or will my project be rolled out to upgrade infrastructure? I can also adjust the cloudflare plan to get more memory. We just want these builds to start working again. Thanks!
This is the deployment id: b239e565-2e26-459b-ae3f-9e1fff07b184

@jhands1 @jfawcett can you see it?