Getting error as cannot allocate memory for creation of docker image during npm install --legacy-peer-deps

Memory limit:19.8 GB
Swap:3 GB
Disk usage limit:176 GB

even though there is enough space available in docker while creating an image getting error as below

785.5 Killed
------
DockerfileAutomation:59
--------------------
  57 |     RUN npm config set strict-ssl false
  58 |     # Install Webpack and Webpack Dev Server globally
  59 | >>> RUN npm install webpack webpack-cli node-sass@7.0.0 --legacy-peer-deps
  60 |
  61 |     # Set environment variables if needed
--------------------
ERROR: failed to solve: ResourceExhausted: process "/bin/sh -c npm install webpack webpack-cli node-sass@7.0.0 --legacy-peer-deps" did not complete successfully: cannot allocate memory

I have exactly the same issue. I have a disk usage limit of 250GB with 4GB swap space and only use 1.7GB on images. The error occurs when building. No containers are running during this build. I don’t know where to look for an explanation, let alone for a solution…

It seems the npm command required too much memory. You can start a container and run the commands interactively while you monitor the memory usage in another terminal.