I could handle the issue on a Linux machine.

On Windows 10 machine, in the container, I run the following command:

export NODE_OPTIONS="--max-old-space-size=20000"

Then, I encountered the following error:

The build failed because the process exited too early. This probably means the system ran out of memory or someone called kill -9 on the process.

I have learned that the issue is swap space:,or%20build%20the%20project%20locally.

I could not increase the swap space of the container on Windows 10 machine but while the space size was 1 GB, it is 2 GB in the container on Linux machine.

Note that I encountered the error I have mentioned above in the first run of npm run build. After this attempt, I tried second run and it built successfully. I could do second run in Dockerfile with following commands:

RUN npm run build; exit 0
RUN npm run build

It is like a try-catch structure.


Node limits it's heap to 512M by default. Passing the environment variable in the RUN command worked for us.

RUN NODE_OPTIONS="--max-old-space-size=8192" yarn build


Adding export NODE_OPTIONS=--max_old_space_size=4096 to package.json solved the problem:

  "build": "export NODE_OPTIONS=--max_old_space_size=4096 && react-scripts build"

And remember you need to increase memory size from Docker settings.


The NODE_OPTIONS solution did not work for me, I am using Node v14 and React Scripts v4.

This solution from GitHub finally helped -


Added to my Dockerfile right before the build command.

enter image description here

Related Query

More Query from same tag