Next.js Discord

Discord Forum

How to debug OOM issue?

Answered
Gharial posted this in #help-forum
Open in Discord
GharialOP
Nextjs v14.1.0 with app and pages router combined.

8 GB RAM

when running yarn build.

Update: it works well after disabled ts check when building the app.
Answered by linesofcode
          yarn vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
          yarn vercel build --token=${{ secrets.VERCEL_TOKEN }}
          yarn vercel deploy --prebuilt --archive=tgz --token=${{ secrets.VERCEL_TOKEN }}
View full answer

46 Replies

what issue is it that you are asking about?
Out of memory?
Google max_old_space_size
GharialOP
the nextjs app will break with OOM on 8GB RAM machine.

and set max_old_space_size didn't work
did you use underscores or dashes?
if you have out of memory issues I bet the issue is in your code vs the machine
maybe a memory leak?
If you suspect its only happening during dev because of the extra resources dev mode takes up
build the app for production and run it on your machine locally using next start
and see if you get an out of memory error
If you do then that increases the chances that its a memory leak in your code
GharialOP
Sorry, the error happens when running yarn build
cc @joulev
honestly this is a hard problem. nextjs does take a lot of resources and there isn't much you can do except giving it more resources, e.g. by getting more RAM and shutting unnecessary apps when running the build to free up the RAM
my laptop is 16GB and i feel it's not enough sometimes
GharialOP
Yes, I also use 16GB machine
don't know if there're any official solutions to debug OOM issues.
hmm
if your're building this locally
is it just to test something?
Because in reality the build would be happening in the cloud in your build / deploy pipeline
if you're hosting on vercel for example they have enough memory on the build machines
or if you're hosting it yourself on a vps somewhere like an ec2 on aws
then you can allocate more resources to it
GharialOP
if you're hosting on vercel for example they have enough memory on the build machines
Vercel machine has only 8GB RAM, so OOM also happens there, have tested.
ah
theres always ec2 or digital ocean
which kinda sucks that you have to go down this road
but thats just the nature of the beast i suppose
(btw that doesnt mean you have to host your app on those instances)
you can pre-build an app elsewhere and then deploy those artifcats to vercel
(if you use vercel)
GharialOP
the company uses Vercel, and I can not change it

and find the root cause is what we want
you can build in a github action and upload the output to vercel via the vercel CLI
the root cause is that nextjs just requires a supercomputer to build at this point
GharialOP
you can pre-build an app elsewhere and then deploy those artifcats to vercel
Seems that it's a good idea, how to do it? 👀

vercel deploy?
one sec
yeah sort of
          yarn vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
          yarn vercel build --token=${{ secrets.VERCEL_TOKEN }}
          yarn vercel deploy --prebuilt --archive=tgz --token=${{ secrets.VERCEL_TOKEN }}
Answer
 yarn vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
          yarn vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
          yarn vercel deploy --prebuilt --prod --archive=tgz --token=${{ secrets.VERCEL_TOKEN }}
actually here is the github action
GharialOP
👀

let me try it
GharialOP
Thank you @linesofcode

It works for me!
You're welcome!
GharialOP
Update: it works well after disabled ts check when building the app.