vercel / vercel/next.js

NextJS build always going out of heap memory when building

Open
#76,704 25 comments 32 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/Falling12/loyalty-backend

To Reproduce
  1. Download the repo
  2. Start a build
  3. Watch the app go out of memory, I also tried giving more memory to nodejs, but 8 gigs wasnt enough too
Current vs. Expected behavior

Whats happening:

  1. The app is building normally until this step: ✓ Generating static pages (18/18)
  2. Then its starting to fill the memory
  3. And then I got the issue: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Excepted behavior:
The app should build normally

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8122
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.14.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 9.15.4
Relevant Packages:
  next: 15.1.7 // There is a newer version (15.2.0) available, upgrade recommended! 
  eslint-config-next: 15.1.7
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

I'm developing this not really large app for a restaurant but recently got this issue where I can't build the app. It can happen that my code is wrong somewhere but I don't really think this. I would be pleased if someone could look into my code aswell. (The build also failed with the same issue when deploying to Vercel)

Thank you for the help in advance!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Clone the linked loyalty-backend repository and reproduce the local next build with Node 22.14.0, Next.js 15.1.7, and the reported memory limit. Start at the build stage after static page generation, then determine whether the failure is reproducible in Next.js or specific to the application. Done means an isolated Next.js defect with a focused reproduction, or clear evidence that no framework change is actionable.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, react, typescript
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.