skip to Main Content

When I try to build in ec2 instance for nextjs app it got stuck I don’t know why? And in local machine the build size is 600mb so I can’t send it to GitHub and pull it on ec2 instance so can anyone tell me what I have to do

Clone the code from GitHub run the npm I command after that npm run build and it got stuck den I tried to ctrl +c command to stop it won’t stop after that I close that ec2 instance and den again I try to open the same instance it won’t opening .I want to know the reason and what steps needed to solve this issue

2

Answers


  1. I’ve encountered this issue several times in the past. It’s because of lack of memory. t2.micro only has 1 GB of memory. Building is relatively memory-intensive so you need adequate amount of it, otherwise it either crash or just hangs.

    As a temporary measure (not recommended) you can try adding a swap space, try at least 4 GB to start. e.g.:

    sudo fallocate -l 4G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    

    If it doesn’t solve the issue, try increasing the swap or better yet get a better specced instance.

    Also, I suggest using tg4.small which has bigger memory and better performance. It’s free at the moment (and has been free for the past 2-3 years). Just keep in mind it is ARM, not x86.

    https://aws.amazon.com/ec2/instance-types/t4/

    Login or Signup to reply.
  2. When building a Next.js project on an EC2 t2.micro instance, you might encounter performance issues due to the limited resources (1 vCPU and 1 GB of memory) available on this instance type. How to solve it? there are many ways to resolve it :

    Upgrade your instance type
    Optimize Your Build
    Increase Swap Space
    or add the following command on npm run build

    NODE_OPTIONS="--max-old-space-size=512" next build
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search