next.js
next.js copied to clipboard
Extremely high memory usage
Verify canary release
- [X] I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: android
Arch: arm64
Version: #2 SMP PREEMPT Fri Aug 5 15:52:33 AST 2022
Binaries:
Node: 18.10.0
npm: 8.19.2
Yarn: 1.22.19
pnpm: N/A
Relevant packages:
next: 13.0.3-canary.0
eslint-config-next: 13.0.2
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
Chrome Canary v109.0.5400.0 (Android)
How are you deploying your application? (if relevant)
Vercel
Describe the Bug
The memory usage on the last next 13 (13.0.3-canary.0 and 13.0.2) releases are too high. next dev
command uses about 1gb of ram. Next 12 is using about 300mb-500mb's of ram.
Expected Behavior
next dev
should use less ram.
Link to reproduction
.
To Reproduce
- Create project with Next 13
- Run
next dev
- Check the ram usage
Probably related to #42349, when I profiled memory half of the heap was strings and they were also increasing with each request
Issue still persists in 13.0.3-canary.1
.
issue still persists in v13.0.3.
I also have this issue.
Same for me. A couple of times a day i get this error. Restarting the dev server helps
Same for me. A couple of times a day i get this error. Restarting the dev server helps
Restarting the server helps but it's annoying to restart the server everytime.
Yeah after the server crashes for JavaScript heap out of memory I just start up the server again, but it's inconvenient and annoying. Also it's taking a lot of memory usage while the app is running, so that's also very annoying since the app is functioning slower and compiling slower (by a lot).
Same for me. A couple of times a day i get this error. Restarting the dev server helps
Don't misunderstand me, this was just meant as a temporarily fix. I also find it extremely annoying and i am worried that this might also happen in production...
Same for me. A couple of times a day i get this error. Restarting the dev server helps
Don't misunderstand me, this was just meant as a temporarily fix. I also find it extremely annoying and i am worried that this might also happen in production...
It'll probably not happen in production since its being compiled while building it and also it's a lot more optimized but yeah that's worrying.
For me it happens in production too, Next 12 was working well with 500 Mb of RAM, now it gets out of memory on the first page reload
Seems to constantly crash for me on Next13

Same problem here !
If a page have lot of <Link>
, Next prebuilt all of these pages resulting high memory consumption and slow down of the app.
Release 13.0.4
seemed to had fixed it for me. You can update by doing:
npm i [email protected] # npm
# or
yarn add [email protected] # yarn
on your current project. It shouldn't break stuff that's already working. Also try to eliminate some dependencies that you don't need or that have a lighter alternative.
Here's the release.
I am on 13.0.4 and it still happened to me a couple of times today. This is the latest stack trace:
`<--- Last few GCs --->
[21540:000001D236F10AA0] 1498088 ms: Mark-sweep 4065.1 (4138.6) -> 4053.0 (4142.6) MB, 270.3 / 0.1 ms (average mu = 0.208, current mu = 0.056) allocation failure scavenge might not succeed
[21540:000001D236F10AA0] 1498502 ms: Mark-sweep 4069.0 (4142.6) -> 4056.9 (4146.6) MB, 396.8 / 0.1 ms (average mu = 0.115, current mu = 0.040) allocation failure scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory 1: 00007FF62B780AAF v8::internal::CodeObjectRegistry::~CodeObjectRegistry+124015 2: 00007FF62B70C866 v8::internal::wasm::WasmCode::safepoint_table_offset+64182 3: 00007FF62B70D8E2 v8::internal::wasm::WasmCode::safepoint_table_offset+68402 4: 00007FF62C041CE4 v8::Isolate::ReportExternalAllocationLimitReached+116 5: 00007FF62C02C2AD v8::SharedArrayBuffer::Externalize+781 6: 00007FF62BECF88C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468 7: 00007FF62BECC9A4 v8::internal::Heap::CollectGarbage+4244 8: 00007FF62BECA320 v8::internal::Heap::AllocateExternalBackingStore+2000 9: 00007FF62BEE8030 v8::internal::FreeListManyCached::Reset+1408 10: 00007FF62BEE86E5 v8::internal::Factory::AllocateRaw+37 11: 00007FF62BEFA68E v8::internal::FactoryBasev8::internal::Factory::AllocateRawArray+46 12: 00007FF62BEFD2CA v8::internal::FactoryBasev8::internal::Factory::NewFixedArrayWithFiller+74 13: 00007FF62BEFD523 v8::internal::FactoryBasev8::internal::Factory::NewFixedArrayWithMap+35 14: 00007FF62BD03B96 v8::internal::HashTablev8::internal::NameDictionary,v8::internal::NameDictionaryShape::EnsureCapacityv8::internal::Isolate+246 15: 00007FF62BD0193A v8::internal::Dictionaryv8::internal::NameDictionary,v8::internal::NameDictionaryShape::Addv8::internal::Isolate+58 16: 00007FF62BD09B66 v8::internal::BaseNameDictionaryv8::internal::NameDictionary,v8::internal::NameDictionaryShape::Add+118 17: 00007FF62BC16858 v8::internal::Runtime::GetObjectProperty+1720 18: 00007FF62C0CF9C1 v8::internal::SetupIsolateDelegate::SetupHeap+494417 19: 000001D23A365117 error Command failed with exit code 134.`
Release
13.0.4
seemed to had fixed it for me. You can update by doing:npm i [email protected] # npm # or yarn add [email protected] # yarn
on your current project. It shouldn't break stuff that's already working. Also try to eliminate some dependencies that you don't need or that have a lighter alternative.
Here's the release.
13.0.4 does not resolve the memory issue for me, still have the random out of memory crashes in development, I haven't encountered any issues in production though.
Release
13.0.4
seemed to had fixed it for me. You can update by doing:npm i [email protected] # npm # or yarn add [email protected] # yarn
on your current project. It shouldn't break stuff that's already working. Also try to eliminate some dependencies that you don't need or that have a lighter alternative. Here's the release.
13.0.4 does not resolve the memory issue for me, still have the random out of memory crashes in development, I haven't encountered any issues in production though.
I know that Material UI has some issues with NextJS 13, so if you're using that I'd suggest removing it and using a lighter solution. If you're not using it, try to remove dependencies that may cause an extremely high memory usage. Of course it's NextJS 13's fault, but removing dependencies might improve it.
This is still happening to me on next 13.0.4
still happening to me
Still bugging for me also 13.0.4
Still happening 13.0.5-canary.4
Still happening for me on 13.0.4 also 😕
For me in 13.0.4 the memory is still high but improved since 13.0.3
Still not fixed in 13.0.5
still happening 13.0.6-canary.2
Same issue here with latest canary. Just after start 2,5GB of ram for a rather simple app, and after a bit of time = crash.
This is an extremely annoying problem. We are a website design agency. We migrated one of our websites to Next.js 13 (13.0.5) and it's using more than 900MBs of RAM. The same site in ASP.NET Core Pages used less than 100 MBs.
Vercel, at least give us hints on how to debug this issue on our side.
The same problem happened to me.
I am using version 13.0.5, and the same problems have occurred frequently in previous versions.
same problem here, using the with apollo example from here https://github.com/vercel/next.js/tree/canary/examples/with-apollo

Hey folks, next.js team member here. I'm investigating this issue. Would anyone care to share with me privately their projects so I can investigate properly? Or a public repro?
@feedthejim sure, I can create a public repo that works with a public API. I need some time though to create it. Maybe a day.