Reputation: 41
I am trying to deploy my nextjs app on EC2 but when I was running npm run build it was getting killed automatically, so I thought it might be because of the ram so I changed my instance type to t3.medium which has 4GB ram but I am still having the same problem.
Upvotes: 4
Views: 4608
Reputation: 7
you need to kill all running processing for that port, the one your app is using
ex:
lsof -i :3000
kill <PID>
if you are running more then one next js apps in droplet or system, for me stopping them all then building worked.
Upvotes: -1
Reputation: 350
The optimization takes place because the ec2 instance does not have enough memory for building available for your Next app to run.
Again, the problem will arise only when running the command
$ npm run build
error due to not having enough memory
and not when you start the next app or run the command
$ npm start
should work as too much memory is not needed.
You have already tried increasing the memory (I do not recommend that as you are changing your instance and paying more for a task that you will run only once and that too can be done on any other machine) by changing the instance type. You can try some other ways:
Option 1: You can try to optimize your Next.js app by removing unnecessary dependencies and minimizing the size of your assets.
Option 2: You can try building the Next.js app on another machine (does not have to be Linux) with more memory and then transfer the build to the EC2 instance using ssh or WinSCP.
Option 3: use a service like AWS Elastic Beanstalk - This service automatically handles provisioning, load balancing, and automatic scaling for your Next.js application.
Option 1 may not be practical so I recommend trying option 2 or 3.
Upvotes: 4