score:1

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:

https://create-react-app.dev/docs/troubleshooting/#:~:text=The%20build%20failed%20because%20the,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.

score:2

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

score:8

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.

score:12

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

This solution from GitHub finally helped - https://github.com/wojtekmaj/react-pdf/issues/496#issuecomment-566200248

GENERATE_SOURCEMAP=false

Added to my Dockerfile right before the build command.

enter image description here


Related Query

More Query from same tag