NextJS build always going out of heap memory when building
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
- Download the repo
- Start a build
- 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:
- The app is building normally until this step: ✓ Generating static pages (18/18)
- Then its starting to fill the memory
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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