#npm ERR! command failed npm ERR! signal SIGKILL` Build Issue

6 messages · Page 1 of 1 (latest)

pseudo oriole
#

We are currently encountering a build issue during the deployment of our application on AWS ECS. The error message indicates that the npm process is being terminated unexpectedly with the signal SIGKILL, suggesting a potential out-of-memory situation.

Here is an overview of the relevant details:

Error Message

npm ERR! command failed npm ERR! signal SIGKILL

Probable Cause:
The issue seems to be related to the --max-old-space-size option, which is used to set the maximum heap size for Node.js. The value currently set to 9048.

Dockerfile (Dev Environment)

    Docker File
  
  # Development

Use the official Node.js image for development

FROM node:18-alpine

Set working directory

WORKDIR /app

Copy package.json and package-lock.json to the container

COPY package*.json ./

Install dependencies

RUN npm install

Copy the whole application to the container

COPY . .

Generate Prisma Client

RUN npx prisma generate

Start the NestJS server in development mode

CMD ["npm", "run", "start:dev"]

Application Start Command (package.json):**
"start:dev": "NODE_OPTIONS=--max-old-space-size=9048 nest start"

Tech Stack:
Nest.js

GraphQL

Prisma

PostgreSQL

Please let me know if anyone can help me on this one.

gloomy fox
#

Where do you build your docker image?

pseudo oriole
#

aws ECS

gloomy fox
#

ECS is where you run your containers, providing an Image from ECR or other Image Repository.

#

If it happens during the container startup/runtime, it's not a Build issue.

Now that I look at the dockerfile though, you actually run the dev instance, which will try to build your app. That's definitely not how you should deploy your app to production.

gloomy fox
#

There's several resources online that should help you understand the optimal process. Here's one: https://wanago.io/2023/01/23/api-nestjs-docker-compose-improvements/

In general, you want to run npm run build in one of your RUN instructions, and use npm run start:prod in your CMD.
Otherwise your container will attempt to run typescript on your codebase, which is expensive operation, and only then it starts your app in watch mode, which also consumes some resources.

Rising max-old-space-size doesn't help anything. It's the ECS that's probably killing your app, you can't change that from within the container.
If you really wanted to run your app in dev mode in ECS, you'd need to go to your Task Definition in AWS console, and raise the memory and CPU reservation for the container there. Also, you'll need to have Capacity Providers large enough to accomodate for such heavy task. That's an awful waste of money, not to mention it's highly insecure to publicly expose development servers.