FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed – JavaScript heap out of memory on nginx

  docker-compose, dockerfile, javascript, nginx, node.js

I am using Django for back-end and i am not doing front-end

When I try to build docker, this error comes out


<--- Last few GCs --->

[24:0x557c8d525880]    51739 ms: Mark-sweep (reduce) 480.2 (495.1) -> 480.1 (493.6) MB, 1552.3 / 0.0 ms  (average mu = 0.108, current mu = 0.002) last resort GC in old space requested
[24:0x557c8d525880]    53295 ms: Mark-sweep (reduce) 480.1 (493.6) -> 480.1 (493.6) MB, 1556.0 / 0.0 ms  (average mu = 0.056, current mu = 0.000) last resort GC in old space requested


<--- JS stacktrace --->

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
The command '/bin/sh -c npm run build' returned a non-zero code: 1
ERROR: Service 'nginx' failed to build : Build failed 

I found a solution on the internet

node --max-old-space-size=1024 index.js

But this code returns this error

    throw err;
    ^

Error: Cannot find module '/root/mer/index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

This is my Dockerfile for nginx

FROM node:16-alpine3.11 as web-build
COPY webapp /webapp
WORKDIR /webapp
RUN npm i
RUN npm run build



FROM nginx:1.19.0-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
COPY --from=web-build /webapp/build /usr/var/nginx/webapp

This Dockerfile for whole project

FROM python:3.8.10
ENV PYTHONUNBUFFERED 1

WORKDIR /meded
RUN pip install --upgrade pip

COPY requirements.txt /meded
RUN pip install -r /meded/requirements.txt

ADD . /meded/

What should front-end do to fix this error?

Source: Dockerfile Questions

LEAVE A COMMENT