Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next 9.5.1 out of memory after some hot reloads #15855

Closed
macrozone opened this issue Aug 4, 2020 · 144 comments
Closed

Next 9.5.1 out of memory after some hot reloads #15855

macrozone opened this issue Aug 4, 2020 · 144 comments
Labels
please add a complete reproduction Please add a complete reproduction.

Comments

@macrozone
Copy link

macrozone commented Aug 4, 2020

Bug report

Describe the bug

Since updating to 9.5.x (from 9.4.x), i get an out of memory error after 10 something hot reloads:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

it did rarely happen in 9.4.1, but it happens very consistantly in 9.5.x

To Reproduce

thats probably tricky. it happens on big projects and might be related to some bug in the hot reload / rebuild. Maybe it happens when there are some import circles?

Expected behavior

nextjs should not go out-of-memory

System information

  • OS:macOS
  • Browser: chrome
  • Version of Next.js: 9.5.1
  • Version of Node.js: 12.13.1

Additional information

we are using a custom server with typescript

@timneutkens timneutkens added the please add a complete reproduction Please add a complete reproduction. label Aug 4, 2020
@timneutkens
Copy link
Member

Please provide a reproduction so that we can investigate

@macrozone
Copy link
Author

Please provide a reproduction so that we can investigate

this is extremly hard to do, but i am 100% sure others have the same issue. Do you hav any idea how this could happen? Its a new problem and happens very consistantly.

maybe circular dependencies? I investigate now in that

@timneutkens
Copy link
Member

but i am 100% sure others have the same issue

Haven't heard anything from our development teams or others, vercel.com is a Next.js app with 250 unique Next.js pages so we would have definitely have run into it if it was as trivial as you're making it to be.

Do you hav any idea how this could happen?

Issues with memory are practically impossible to investigate without having the application so now I can't give you pointers on where to look. You'll have to run tooling to track down where memory is allocated (e.g. the Node.js debugger profiler).

If it makes it any easier to share the application we can also investigate it under (paid) enterprise support if that makes the company you work for share the application, which will likely save your development team significant amounts of time.

@macrozone
Copy link
Author

but i am 100% sure others have the same issue

Haven't heard anything from our development teams or others, vercel.com is a Next.js app with 250 unique Next.js pages so we would have definitely have run into it if it was as trivial as you're making it to be.

Do you hav any idea how this could happen?

Issues with memory are practically impossible to investigate without having the application so now I can't give you pointers on where to look. You'll have to run tooling to track down where memory is allocated (e.g. the Node.js debugger profiler).

If it makes it any easier to share the application we can also investigate it under (paid) enterprise support if that makes the company you work for share the application, which will likely save your development team significant amounts of time.

will think abou that, thank you

@jjaybrown
Copy link

We are also seeing the same problem, including in production, I can't provide a reproduction due to sensitivity, but I can provide a next.config and plugins/env if that would be acceptable?

@timneutkens
Copy link
Member

timneutkens commented Aug 4, 2020

I can't provide a reproduction due to sensitivity, but I can provide a next.config and plugins/env if that would be acceptable?

Unlikely we'll be able to track it down based on just a next.config.js.

As said before if the only concern is that the code is sensitive we can look at enterprise support which would include a NDA.

@chrysb

This comment has been minimized.

@macrozone
Copy link
Author

I tried to debug it with profiler,

i just see that the app takes roughly 1.6 - 1.9 GB just after the first page compilation. Maybe its just too big for nextjs to handle.

I noticed that webpack seems to cache a lot of sources in memory:

Bildschirmfoto 2020-08-07 um 10 25 10

@macrozone
Copy link
Author

i tried now setting NODE_OPTIONS='--max_old_space_size=4096' and it seems to be better at first glance

@timneutkens
Copy link
Member

@macrozone I'd really like to have a look at the application myself as it's pretty much impossible to judge if that's a problem based on that one screenshot. E.g. the compilation object is only holding 200mb of memory

@macrozone
Copy link
Author

@timneutkens ok, can you send me a message? (my work email should be under my account)

@daveteu
Copy link

daveteu commented Aug 15, 2020

I have been experiencing memory leak since 9.5.2 (I updated yesterday). I was working on the /api/ files yesterday and this morning when it will randomly crash during hot reloads.

Since today afternoon, I was working on material-ui and some api

After I kept making changes to makeStyles, and changing the classes back and forth (because I'm trying to get the layout right), then it will crash after quite a few hot reload compiling.

Below, shows the number of hot reloads (in between the 2 crashes, I was working on material-ui's makeStyles and adding/removing classes to different component) and compiles while I'm playing with makeStyles and material-ui's Accordion component.

I'm not sure whether the logs below help, but I have to say the crashes are all pretty random, so far crashed about 10-15 times in the span of 24 hours, sometimes when working on /api/ sometimes while working on material-ui.

wait - compiling...

<--- Last few GCs --->

[3511:0x4ac6840] 1722755 ms: Scavenge 454.2 (462.5) -> 451.2 (463.0) MB, 3.2 / 0.1 ms (average mu = 0.984, current mu = 0.618) allocation failure
[3511:0x4ac6840] 1722796 ms: Scavenge 455.0 (463.0) -> 451.5 (463.0) MB, 1.8 / 0.0 ms (average mu = 0.984, current mu = 0.618) allocation failure
[3511:0x4ac6840] 1723246 ms: Mark-sweep 474.1 (484.8) -> 461.6 (482.1) MB, 400.5 / 0.1 ms (average mu = 0.987, current mu = 0.989) allocation failure scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
1: 0xa3ac30 node::Abort() [node]
2: 0x98a45d node::FatalError(char const*, char const*) [node]
3: 0xbae25e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
4: 0xbae5d7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xd56125 [node]
6: 0xd8178e v8::internal::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject, int) [node]
7: 0xd8da96 v8::internal::FullEvacuator::RawEvacuatePage(v8::internal::MemoryChunk*, long*) [node]
8: 0xd7b4ef v8::internal::Evacuator::EvacuatePage(v8::internal::MemoryChunk*) [node]
9: 0xd7b768 v8::internal::PageEvacuationTask::RunInParallel(v8::internal::ItemParallelJob::Task::Runner) [node]
10: 0xd70dc9 v8::internal::ItemParallelJob::Run() [node]
11: 0xd8fbfe void v8::internal::MarkCompactCollectorBase::CreateAndExecuteEvacuationTasks<v8::internal::FullEvacuator, v8::internal::MarkCompactCollector>(v8::internal::MarkCompactCollector*, v8::internal::ItemParallelJob*, v8::internal::MigrationObserver*, long) [node]
12: 0xd90494 v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [node]
13: 0xd90665 v8::internal::MarkCompactCollector::Evacuate() [node]
14: 0xda1857 v8::internal::MarkCompactCollector::CollectGarbage() [node]
15: 0xd63dd9 v8::internal::Heap::MarkCompact() [node]
16: 0xd64c0b v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
17: 0xd65684 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
18: 0xd680fc v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
19: 0xd2f3aa v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [node]
20: 0xd29254 v8::internal::FactoryBasev8::internal::Factory::AllocateRawWithImmortalMap(int, v8::internal::AllocationType, v8::internal::Map, v8::internal::AllocationAlignment) [node]
21: 0xd2b5a1 v8::internal::FactoryBasev8::internal::Factory::NewRawTwoByteString(int, v8::internal::AllocationType) [node]
22: 0xf89565 v8::internal::String::SlowFlatten(v8::internal::Isolate*, v8::internal::Handlev8::internal::ConsString, v8::internal::AllocationType) [node]
23: 0xbc1369 v8::String::Utf8Length(v8::Isolate*) const [node]
24: 0xa13067 [node]
25: 0xc19bab [node]
26: 0xc1b156 [node]
27: 0xc1b7d6 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
28: 0x13f5159 [node]
Aborted (core dumped)
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! [email protected] dev: next dev -p 6000
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2020-08-15T17_43_39_015Z-debug.log
ubuntu@ip-172-31-35-196:~/project2$ npm run dev

[email protected] dev /home/ubuntu/project
next dev -p 6000

info - Loaded env from /home/ubuntu/project2/.env.local
ready - started server on http://localhost:6000
event - compiled successfully
event - build page: /next/dist/pages/_error
wait - compiling...
event - compiled successfully
event - build page: /dashboard/customer/[pid]
wait - compiling...
event - compiled successfully
event - build page: /api/dashboard/[[...path]]
wait - compiling...
event - compiled successfully
wait - compiling...
event - compiled successfully
wait - compiling...
event - compiled successfully
event - build page: /api/dashboard/[[...path]]
wait - compiling...
event - compiled successfully
wait - compiling...
event - compiled successfully
wait - compiling...
event - compiled successfully
wait - compiling...
error - ./src/components/Dashboard/Activity.js:25:25
Syntax error: Identifier directly after number

23 | accordionExpandedNoExtraMargin: {
24 |

25 | minHeight: 48px !important'
| ^
26 | },
27 | expandNothing: {
28 |
wait - compiling...
event - compiled successfully
event - build page: /dashboard
wait - compiling...
event - compiled successfully
wait - compiling...
event - compiled successfully
wait - compiling...
event - compiled successfully
wait - compiling...
<--- Last few GCs --->

[3573:0x503a840] 357009 ms: Scavenge 454.7 (462.2) -> 452.0 (462.9) MB, 3.1 / 0.0 ms (average mu = 0.950, current mu = 0.668) allocation failure
[3573:0x503a840] 357025 ms: Scavenge 456.3 (464.6) -> 454.2 (465.1) MB, 2.7 / 0.0 ms (average mu = 0.950, current mu = 0.668) allocation failure
[3573:0x503a840] 357472 ms: Mark-sweep 476.2 (486.9) -> 456.4 (481.3) MB, 382.0 / 0.1 ms (average mu = 0.990, current mu = 0.994) allocation failure scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
1: 0xa3ac30 node::Abort() [node]
2: 0x98a45d node::FatalError(char const*, char const*) [node]
3: 0xbae25e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
4: 0xbae5d7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]

@macrozone
Copy link
Author

We use styled-components (latest version 5.1.1), which similarly to material-ui creates global styes that will be injected into the head. Maybe the improvements of hot reloading interfers with that?

@sbinlondon
Copy link

sbinlondon commented Aug 19, 2020

I've been having the same issue for about 1-2 weeks as well. After starting up my local dev environment, I work for a bit and then end up having to restart due to a crash. I also get these report.*.json files put into my root directory. This has happened most days.

System information

  • OS: MacOS Catalina 10.15.6
  • Browser: Firefox 79
  • Version of Next.js: 9.5.1 (upgraded 15 days ago) & continuing in 9.5.2 (upgraded 8 days ago)
  • Version of Node.js: 12.16.1 (with NVM)

(I can provide the full Node-generated report JSON if needed).

A coworker and I also noticed we were getting this error too:

TypeError: Cannot destructure property 'components' of 'object null' as it is null.
    at DevServer.renderToHTMLWithComponents (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/next-server/server/next-server.js:60:246)
    at DevServer.renderErrorToHTML (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/next-server/server/next-server.js:101:332)
    at async DevServer.renderErrorToHTML (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/server/next-dev-server.js:30:1204)
    at async DevServer.renderError (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/next-server/server/next-server.js:100:1173)
TypeError: Cannot destructure property 'components' of 'object null' as it is null.
    at DevServer.renderToHTMLWithComponents (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/next-server/server/next-server.js:60:246)
    at DevServer.renderErrorToHTML (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/next-server/server/next-server.js:101:332)
    at async DevServer.renderErrorToHTML (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/server/next-dev-server.js:30:1204)
    at async DevServer.renderToHTML (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/next-server/server/next-server.js:100:974)
    at async DevServer.renderToHTML (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/server/next-dev-server.js:30:578)
    at async DevServer.render (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/next-server/server/next-server.js:55:236)
TypeError: Cannot destructure property 'components' of 'object null' as it is null.
    at DevServer.renderToHTMLWithComponents (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/next-server/server/next-server.js:60:246)
    at DevServer.renderErrorToHTML (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/next-server/server/next-server.js:101:332)
    at async DevServer.renderErrorToHTML (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/server/next-dev-server.js:30:1204)
    at async DevServer.renderToHTML (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/next-server/server/next-server.js:100:974)
    at async DevServer.renderToHTML (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/server/next-dev-server.js:30:578)
    at async DevServer.render (/Users/katebeard/coding/opencollective/opencollective-frontend/node_modules/next/dist/next-server/server/next-server.js:55:236)

Please provide a reproduction so that we can investigate

When you say this do you mean a link to a PR with a live app on Vercel? We might be able to provide since Open Collective is open source and all our repos are open. (Edited to add: here's the PR I've been working on where I experienced the latest crashes, you can pull the code from our repo and see the Vercel app link in the PR.)

@sbinlondon
Copy link

Quick follow up: these are some messages I've been getting in my terminal warning of a memory leak.

Screenshot 2020-08-19 at 18 45 48

Screenshot 2020-08-19 at 18 46 11

It points specifically to this file in our frontend repo, which has an unnamed default export. It's one of the oldest files in our repo and definitely wasn't causing issues before. Perhaps there's been a change in the way Next.js handles these default unnamed exports that would cause the memory leak? This for example seems to be a new addition released within the last few weeks that was flagging that particular error, and warning of a memory leak.

I played around making some changes to a component I've been working on this week while the crashes have been most notable, and was able to trigger one again just now.

Here's the output from my terminal:

wait  - compiling...
event - compiled successfully
event - build page: /editCollective
wait  - compiling...
event - compiled successfully
event - build page: /collective-page
wait  - compiling...
event - compiled successfully
wait  - compiling...

<--- Last few GCs --->

[15737:0x102925000]  5850165 ms: Mark-sweep 2052.8 (2068.5) -> 2051.9 (2068.5) MB, 419.6 / 0.2 ms  (average mu = 0.783, current mu = 0.000) last resort GC in old space requested
[15737:0x102925000]  5850866 ms: Mark-sweep 2051.9 (2068.5) -> 2051.5 (2067.8) MB, 701.2 / 0.1 ms  (average mu = 0.602, current mu = 0.000) last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x2bc03c1408d1 <JSObject>
    0: builtin exit frame: byteLength(aka byteLengthUtf8)(this=0x2bc07bf6fd89 <Object map = 0x2bc0a06a4ba9>,0x2bc09252c761 <Very long string[34224816]>,0x2bc07bf6fd89 <Object map = 0x2bc0a06a4ba9>)

    1: fromString(aka fromString) [0x2bc07bf67d79] [buffer.js:~424] [pc=0x2784c0fe4651](this=0x2bc0bd7c04b1 <undefined>,0x2bc09252c761 <Very long string[34224816]>,0x2bc0eba27999 <String[#4]: utf8>)
...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 0x100080c68 node::Abort() [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
 2: 0x100080dec node::errors::TryCatchScope::~TryCatchScope() [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
 3: 0x100185167 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
 4: 0x100185103 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
 5: 0x10030b2f5 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
 6: 0x1003130ed v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
 7: 0x1002e273c v8::internal::Factory::NewRawTwoByteString(int, v8::internal::AllocationType) [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
 8: 0x100533c81 v8::internal::String::SlowFlatten(v8::internal::Isolate*, v8::internal::Handle<v8::internal::ConsString>, v8::internal::AllocationType) [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
 9: 0x1001a42ad v8::String::Utf8Length(v8::Isolate*) const [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
10: 0x100064354 node::Buffer::(anonymous namespace)::ByteLengthUtf8(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
11: 0x1001f08f0 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
12: 0x1001efecf v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
13: 0x1001ef5d0 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
14: 0x100950a19 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/Users/katebeard/.nvm/versions/node/v12.16.1/bin/node]
15: 0x2784c0fe4651 
zsh: abort      npm run dev
~/coding/opencollective/opencollective-frontend  (git)-[master]- -> 

Node had been using around ~1.9 GB for a while and I'm not sure if it helped trigger it or if it was coincidence but when I switched branches and made a few more changes that seemed to push it over the edge of the available 2GB of memory.

@helsont
Copy link

helsont commented Sep 3, 2020

I've noticed this issue happen 4 -5 times in the past month. It has happened when switching branches, but it also just happened when I updated my JSX to have an inline style. I tend to run yarn dev for multiple days on end.

wait  - compiling...
event - compiled successfully
wait  - compiling...
event - compiled successfully
wait  - compiling...

<--- Last few GCs --->
nce start of marking 305 ms) (average mu = 0.778, current mu = 0.186) allocatio[20536:0x104091000] 57744365 ms: Mark-sweep 2083.8 (2090.9) -> 2083.8 (2090.9) MB, 346.4 / 0.0 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 394 ms) (average mu = 0.651, current mu = 0.121) last reso[20536:0x104091000] 57744720 ms: Mark-sweep 2083.8 (2090.9) -> 2083.7 (2090.9) MB, 354.6 / 0.0 ms  (average mu = 0.483, current mu = 0.000) last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x1007538f9]
    1: StubFrame [pc: 0x1007964e0]
Security context: 0x3eb61e880921 <JSObject>
    2: replace [0x3eb61e88cdd1](this=0x3eb6896a1cc9 <Very long string[29761]>,0x3eb61dbdef61 <JSRegExp <String[#10]: \n(?=.|\s)>>,0x3eb6c6363451 <String[9]\: \n/******/>)
    3: source [0x3eb61dbdfaf1] [/Users/helson/Development/polyops/ui/node_modules/webpack-sources/lib/PrefixSource.js:43] [bytecode=0x3eb6c634d381 offset=60]...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 0x100080a4c node::Abort() [/usr/local/Cellar/node/13.13.0_2/bin/node]
 2: 0x100080bc2 node::OnFatalError(char const*, char const*) [/usr/local/Cellar/node/13.13.0_2/bin/node]
 3: 0x100180be5 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/Cellar/node/13.13.0_2/bin/node]
 4: 0x100180b8f v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/Cellar/node/13.13.0_2/bin/node]
 5: 0x10029a5c3 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/Cellar/node/13.13.0_2/bin/node]
 6: 0x10029facc v8::internal::Heap::SetUp() [/usr/local/Cellar/node/13.13.0_2/bin/node]
 7: 0x10027ca79 v8::internal::Factory::AllocateRawWithImmortalMap(int, v8::internal::AllocationType, v8::internal::Map, v8::internal::AllocationAlignment) [/usr/local/Cellar/node/13.13.0_2/bin/node]
 8: 0x10027ee6c v8::internal::Factory::NewRawOneByteString(int, v8::internal::AllocationType) [/usr/local/Cellar/node/13.13.0_2/bin/node]
 9: 0x100441a9f v8::internal::String::SlowFlatten(v8::internal::Isolate*, v8::internal::Handle<v8::internal::ConsString>, v8::internal::AllocationType) [/usr/local/Cellar/node/13.13.0_2/bin/node]
10: 0x1004bb6d9 v8::internal::RegExpImpl::IrregexpExec(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSRegExp>, v8::internal::Handle<v8::internal::String>, int, v8::internal::Handle<v8::internal::RegExpMatchInfo>) [/usr/local/Cellar/node/13.13.0_2/bin/node]
11: 0x100504307 v8::internal::Runtime_RegExpExec(int, unsigned long*, v8::internal::Isolate*) [/usr/local/Cellar/node/13.13.0_2/bin/node]
12: 0x1007538f9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/Cellar/node/13.13.0_2/bin/node]
13: 0x1007964e0 Builtins_RegExpReplace [/usr/local/Cellar/node/13.13.0_2/bin/node]
14: 0x100740ae2 Builtins_StringPrototypeReplace [/usr/local/Cellar/node/13.13.0_2/bin/node]
error Command failed with signal "SIGABRT".

@lclc98
Copy link

lclc98 commented Sep 11, 2020

I seem to get this crash after I change some CSS in the same file as tailwind imports, I am also using typescript. I am currently trying to create a test repo. Repo based on blog-starter-typescript but slightly modified https://github.com/lclc98/NextOOM

@stevez86
Copy link

stevez86 commented Oct 1, 2020

I've been getting this issue consistently after 1-2 hot reloads after upgrading to 9.5. It makes the dev experience slow (constantly restarting) and barely usable. The OOM occurred on 9.4 but much less frequently (once an hour) Has anyone been able to improve / resolve this issue?

@timneutkens it looks like we have a few repros, I can also throw mine into the mix but would need to be under an NDA.

@stevez86
Copy link

stevez86 commented Oct 1, 2020

FYI anyone having issues I was able to greatly reduce this by removing the headers function in my next config.

@nandorojo
Copy link

nandorojo commented Oct 13, 2020

I've been getting this error with 9.5 as my site has grown in size. It happens whenever I fast refresh and have been in dev mode for over 15 minutes. I could share my repo privately if it's helpful @timneutkens

Update, fixed

I refactored my entire app to make sure that there was absolutely no circular importing. I also changed my package.json script to run with this:

{
  "scripts": {
    "start": "NODE_OPTIONS=--max_old_space_size=8192 next"
  }
}

Now it's working just fine. Not sure what did it exactly, but I have a feeling it was a circular imports. So I recommend making sure you don't have circular imports in your app.

For context, I'm on [email protected]. I'm also using Expo + Next.js, and I upgraded to Expo SDK39 from 38 and react-native-web 0.14. Unsure if that had anything to do with it or not. 🤷🏼‍♂️

@jackocnr
Copy link

jackocnr commented Oct 13, 2020

FWIW I was getting this error using an old version of Node (v10.15.3), and I stopped getting it after I upgraded to v12.18.4.

Edit: nope, it just stopped for a while, then came back 😞

@bkniffler
Copy link

bkniffler commented Oct 20, 2020

Also happening to me since a few months now. I'm always on the latest version of nextjs and I'm using libraries such as elastic-ui, less, graphql (via urql), typescript. Its happening quite frequently, I'd say every 30-60 minutes of working, and always after the wait - compiling... step, so I guess its got something to do with hot reloading / fast refreshing.

<--- Last few GCs --->

[82128:0x102a81000]  5231616 ms: Mark-sweep 2091.9 (2100.2) -> 2091.6 (2100.2) MB, 260.0 / 0.1 ms  (average mu = 0.584, current mu = 0.000) last resort GC in old space requested
[82128:0x102a81000]  5231884 ms: Mark-sweep 2091.6 (2100.2) -> 2090.3 (2100.2) MB, 267.7 / 0.0 ms  (average mu = 0.393, current mu = 0.000) last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x1009031ed]
Security context: 0x114e2ee408d1 <JSObject>
    1: fromStringFast(aka fromStringFast) [0x114ed3830861] [buffer.js:~419] [pc=0x10518a017a5d](this=0x114e903404b1 <undefined>,0x114e8f155aa1 <Very long string[32212516]>,0x114ed38387d9 <Object map = 0x114ef48e5059>)
    2: fromString(aka fromString) [0x114ed38308a1] [buffer.js:452] [bytecode=0x114ebda2bd59 offset=117](this=0x114e903404b1 <undefined>,0x114e8f1...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 0x1010285f9 node::Abort() (.cold.1) [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]
 2: 0x10008634d node::FatalError(char const*, char const*) [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]
 3: 0x10008648e node::OnFatalError(char const*, char const*) [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]
 4: 0x100187c07 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]
 5: 0x100187ba7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]
 6: 0x100315955 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]
 7: 0x10031d9fc v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]
 8: 0x1002ed7db v8::internal::Factory::NewRawTwoByteString(int, v8::internal::AllocationType) [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]
 9: 0x1005561e2 v8::internal::String::SlowFlatten(v8::internal::Isolate*, v8::internal::Handle<v8::internal::ConsString>, v8::internal::AllocationType) [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]
10: 0x1001a5a6d v8::String::Utf8Length(v8::Isolate*) const [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]
11: 0x10006976e node::Buffer::(anonymous namespace)::ByteLengthUtf8(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]
12: 0x1009031ed Builtins_CallApiCallback [/Users/bkniffler/.nvm/versions/node/v12.16.3/bin/node]

@nodkz
Copy link

nodkz commented Oct 20, 2020

I'm also using less. I suppose that problem somewhere with webpack & less-loader.

@matteing
Copy link

Having this issue, increasing in severity + frequency lately.

<--- Last few GCs --->

[6948:0x102888000] 12101179 ms: Mark-sweep 2097.6 (2110.7) -> 2097.5 (2110.5) MB, 310.4 / 0.0 ms  (average mu = 0.954, current mu = 0.001) last resort GC in old space requested
[6948:0x102888000] 12101498 ms: Mark-sweep 2097.5 (2110.5) -> 2096.2 (2110.0) MB, 318.6 / 0.0 ms  (average mu = 0.908, current mu = 0.000) last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x0f6e59c408a1 <JSObject>
    0: builtin exit frame: byteLength(aka byteLengthUtf8)(this=0x0f6e2b3342a1 <Object map = 0xf6e19765b91>,0x0f6eabbb3759 <Very long string[9587152]>,0x0f6e2b3342a1 <Object map = 0xf6e19765b91>)

    1: fromStringFast(aka fromStringFast) [0xf6e2b32bba1] [buffer.js:398] [bytecode=0xf6eab716b71 offset=7](this=0x0f6ea06c04a9 <undefined>,0x0f6eabbb3759 <Very long string[9587152]>,0x0f6e2b3342a1 <Obj...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 0x10007f231 node::Abort() [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
 2: 0x10007f3b5 node::OnFatalError(char const*, char const*) [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
 3: 0x100176887 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
 4: 0x100176823 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
 5: 0x1002fa9d5 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
 6: 0x100302788 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
 7: 0x1002d15c3 v8::internal::Factory::NewRawTwoByteString(int, v8::internal::AllocationType) [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
 8: 0x100517c71 v8::internal::String::SlowFlatten(v8::internal::Isolate*, v8::internal::Handle<v8::internal::ConsString>, v8::internal::AllocationType) [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
 9: 0x10019559d v8::String::Utf8Length(v8::Isolate*) const [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
10: 0x100062306 node::Buffer::(anonymous namespace)::ByteLengthUtf8(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
11: 0x1001e1ba0 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
12: 0x1001e117f v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
13: 0x1001e0880 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
14: 0x1009312f9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/Users/sergio/.nvm/versions/node/v12.14.1/bin/node]
[1]    6946 abort      npm run dev

@mikestopcontinues
Copy link

I'm getting this too, at least once or twice per full coding day. I rarely reset my dev server unless this happens.

<--- Last few GCs --->

[4189:0x108008000] 57528940 ms: Mark-sweep 2043.9 (2057.4) -> 2043.6 (2057.4) MB, 296.9 / 0.1 ms  (average mu = 0.847, current mu = 0.000) last resort GC in old space requested
[4189:0x108008000] 57529232 ms: Mark-sweep 2043.6 (2057.4) -> 2042.4 (2057.4) MB, 292.6 / 0.1 ms  (average mu = 0.739, current mu = 0.000) last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x10096318d]
Security context: 0x0d0130dc08d1 <JSObject>
    1: from [0xd01da971429] [buffer.js:~304] [pc=0x1ebb7473ac17](this=0x0d01a72cd061 <JSFunction Buffer (sfi = 0xd01da967bf9)>,0x0d01b079fac1 <Very long string[18934961]>,0x0d01da969bf9 <String[#4]: utf8>,0x0d01bddc04b1 <undefined>)
    2: writeOut(aka writeOut) [0xd01f8106219] [/Users/msc/Code/@sitearcade/hub/node_modules/webpack/lib/Compiler.js:457] [bytecode...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 0x1011d1cc5 node::Abort() (.cold.1) [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
 2: 0x10009f919 node::Abort() [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
 3: 0x10009fa7f node::OnFatalError(char const*, char const*) [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
 4: 0x1001e38b7 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
 5: 0x1001e3857 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
 6: 0x10036b9e5 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
 7: 0x100373a8c v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
 8: 0x1003435fb v8::internal::Factory::NewRawTwoByteString(int, v8::internal::AllocationType) [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
 9: 0x1005ab2d2 v8::internal::String::SlowFlatten(v8::internal::Isolate*, v8::internal::Handle<v8::internal::ConsString>, v8::internal::AllocationType) [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
10: 0x10020171d v8::String::Utf8Length(v8::Isolate*) const [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
11: 0x10007e69b node::Buffer::(anonymous namespace)::ByteLengthUtf8(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
12: 0x10096318d Builtins_CallApiCallback [/Users/msc/.nvm/versions/node/v12.18.4/bin/node]
sh: line 1:  4188 Abort trap: 6

@sharanya5
Copy link

I'm facing the same issue if I don't keep restarting the server now and then, and after updating to the latest version there seems to be an issue with hot reloading too. Sometimes I have to refresh the site manually.

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

@naseef0
Copy link

naseef0 commented Oct 27, 2020

I have the same issue... i updated next version to v9.5.0. after that i got memory heap issue.

Tried this also.. export NODE_OPTIONS="--max_old_space_size=6096.
Getting issue after 2 or 3 Route changing.

Screenshot 2020-10-27 at 1 32 17 PM

@bkniffler
Copy link

Still happening with latest v10, in case anyone was hoping it could've been solved by chance.

@jdfm
Copy link

jdfm commented Oct 28, 2020

I can also confirm that this is happening. It seems like it may be related to page navigation somehow, as, when trying to come up with reproducible steps, we noticed that if we stayed on the same page and tried a series of change+save loops to get the hot reloading to fire quickly, it wouldn't crash. But, if we tried navigating through our app for a bit, and then doing a few change+save loops we would quickly get to a point where it crashed.

A few properties of the codebase I'm working on:

  • We use styled-components (currently at v5.1.0) and we have a babel.config.js file that we use so we can properly SSR the styles (mentioning this because of what was reported [Next 9] out of memory when building the app  #7929 (comment))
  • We use Typescript in the codebase (currently at v4.0.3)
  • We are currently on NextJS v9.5.5 (upgraded recently from v9.3.6)
  • We have a number of circular dependencies in our codebase
  • There are a lot of components in our codebase, ranging from ones we created ourselves to ones we import via component libraries that were created in house

As far as I know, no one on our team had this issue on NextJS v9.3.6.

@Alounv
Copy link

Alounv commented May 19, 2021

i wonder if this PR will fix some of the issues we are seeing here: #24282
Can someone try that patch locally and see if that makes a difference?

Hey, it seems that going to Next 10.2.1 (including #24282) + using webpack5 has solved the issue in my case.
The memory is now stable and in particular the (string) instances (source-map ?) in the heap snapshot that used to grow to several Gb are now stable and less than 300 Mb.

@joeplaa
Copy link

joeplaa commented May 25, 2021

As suggested by @Alounv I updated next. I'm currently on v10.2.2. The issue got even worse in my demo above which wouldn't start at all now. I had to update the minimum amount of memory from 128 to 160mb.

To get some realistic feedback I removed set NODE_OPTIONS=--max-old-space-size=8192 from the projects' package.json that I'm currently working on. Unfortunately it still crashes after a while although it felt to take longer, but that is just subjective.

@Alounv
Copy link

Alounv commented May 25, 2021

To get some realistic feedback I removed set NODE_OPTIONS=--max-old-space-size=8192 from the projects' pa

Are you using webpack5?

@joeplaa
Copy link

joeplaa commented May 25, 2021

Are you using webpack5?

Yes

@chris-erickson
Copy link

chris-erickson commented May 25, 2021

I don't know if this is useful, but I found that some React components were loading the Link element with bad urls. The errors weren't really exposed until I removed most of my pages from generation. There were some other issues but this was a big one. It might be good to have Next.js report more of it's lifecycle data so it's easier to pinpoint where things are happening, or some way to die on errors so they can be located.

Anyways, seems one thing I learned was to cut down your generated pages to as few as possible and add them back in until you see errors so you see them.

Update 1: We have a big json file that's a mapping of zip codes to coordinates. This was require d in one of our API files. I changed it to a .js file and imported it import { zipMap } from 'lib/zipToCoordinates.js' and that resolved one more OOM error that had zero context.

@Robbie-Cook
Copy link

Deleting my .next folder and running npm run dev seems to work for me. For me, this error happens when lerna publishing.

@Dunky45
Copy link

Dunky45 commented Jun 29, 2021

Just want to add my experience with this and spill some of my toughts. As the others said here. I'm also experiencing this issue in dev since upgrading to 9.5 and in other project to latest 10.x. . It often crashes during some CSS work or just when we navigate throughout the project (maybe some hot-reload cache accumulating). On 9.5 I use SASS with next-sass lib and on 10.x styled components. I just keep my fingers crossed it won't happen in production 😄 , so far it hasn't but you never know.

To be honest I don't feel confident that the leaks can't be somewhere in my code. I tried debugging snapshots but it's just too much information for me and I would say that orienting in this kind of deep debugging is for real senior hot-shots. (I've been working with react since 2017 and can't rly understand much).

From my point of view trying to "fix" it with giving access to more RAM is just pointless, THAS IS JUST NO FIX AT ALL and you just keep increasing the cost of your app.

I totally understand that guys from Vercel are in tough spot here, since helping with issue that you hardly can reproduce is almost impossible. But we can all agree that something has changed guys, too many devs have this problem and it shouldn't be overlooked.

Btw. Thanks for your work nevertheless, best framework out here still! 👍

Ok so for me the issue was it seem this:

I have folder named components, where i have a lot of small components that app re-uses.
In that folder i had index.js file, which exported all those components, so i could import them in pages/views like this:

import {ComponentA, ComponentB, ComponentC} from './components'

I removed index.js and changed all the imports, to direct imports e.g. :

import ComponentA from './components/ComponentA'

After i did this in whole project (maaan was this a painfull job for many many hours 🤮 😭 ) it seems that the problem with memory leak no longer occurs (haven't got a single error in a month).

Hope that someone has the problem as I did and it will help him :).
Happy coding!

@georgiosd
Copy link

georgiosd commented Jun 29, 2021 via email

@Dunky45
Copy link

Dunky45 commented Jun 29, 2021

Weird. So tree shaking doesnt work if you import + re-export?

I was also surprised, I'm not sure to this day if something was wrong with my setup, but tree shaking was not working for me it seems. Also my initial build size is now HALF of what it was before... 🤯

@laurensnl
Copy link

laurensnl commented Jun 29, 2021

I have folder named components, where i have a lot of small components that app re-uses.
In that folder i had index.js file, which exported all those components, so i could import them in pages/views like this:

import {ComponentA, ComponentB, ComponentC} from './components'

I removed index.js and changed all the imports, to direct imports e.g. :

import ComponentA from './components/ComponentA'

I bet you tried to find something before you started this endeavour, but does anybody by any chance know if there's an automated way to do this (using VSCode)?

I'm using the same method of importing components by means of index.ts files in every sub-folder, all rooting down to ./components/, for code clarity. I had the out of memory problem for a while but I'm not experiencing it anymore in the latest version of NextJS. Tree shaking indeed doesn't seem to work if you import your components this way, so I'd like to try importing the components from their files directly to see the change in build size, but preferably without spending a day on rewriting all imports!

@jdfm
Copy link

jdfm commented Jun 29, 2021

So, #12557 is probably relevant to this issue.

[...] does anybody by any chance know if there's an automated way to do this [...]

I ended up building a codemod for our codebase using ts-morph to refactor away all of our barrels. The end result was an improvement to our jest runtimes (improved by 200s), our NextJS build times (20-30s improvements), a reduction in the number of circular dependencies (269 to 127), improved bundle chunking and an overall reduction in First Load JS (about 1MB to 840KB or so) for most pages controlled by our codebase.

I'll try checking if I can release the codemod to the general public.

I would recommend getting rid of barrel files if all of the consumers of your code are within the same codebase. If there are consumers of your code outside of your codebase, and you really want those barrel files, have something to generate the barrels as a build artifact to help you avoid the creation of unintended circular dependencies, among other issues, while also providing a nice public api for your code.

@tizmagik
Copy link

I'll try checking if I can release the codemod to the general public.

@jdfm That would be much appreciated! 🙏 If you need any help, happy to assist.

@laurensnl
Copy link

That would be awesome @jdfm!

It seemed to be the most logical way to use barrels by the time we started the project, not knowing that circular dependencies would be an issue and that tree shaking wouldn't work.

@Dunky45
Copy link

Dunky45 commented Jun 29, 2021

I bet you tried to find something before you started this endeavour, but does anybody by any chance know if there's an automated way to do this (using VSCode)?

I did, but i was worried that if i would let some script do the works I would end up with many errors and loose my head around. By doing it myself I was sure every import is correct, of course human error is a biggie here. But thankfully I am kinda good at this "copy-paste-robot like" things 😆.
Anyway, there must be for sure a way to script this process quite easily.

Also like others said, thanks to this there are improvements in build size, build speed and jest runtimes.

@joeplaa
Copy link

joeplaa commented Jul 8, 2021

Ok so for me the issue was it seem this:

I have folder named components, where i have a lot of small components that app re-uses.
In that folder i had index.js file, which exported all those components, so i could import them in pages/views like this:

import {ComponentA, ComponentB, ComponentC} from './components'

I removed index.js and changed all the imports, to direct imports e.g. :

import ComponentA from './components/ComponentA'

After i did this in whole project (maaan was this a painfull job for many many hours 🤮 😭 ) it seems that the problem with memory leak no longer occurs (haven't got a single error in a month).

Hope that someone has the problem as I did and it will help him :).
Happy coding!

This didn't work for us. We still get the JavaScript heap out of memory error.

@usman087
Copy link

usman087 commented Jul 8, 2021

So, #12557 is probably relevant to this issue.

[...] does anybody by any chance know if there's an automated way to do this [...]

I ended up building a codemod for our codebase using ts-morph to refactor away all of our barrels. The end result was an improvement to our jest runtimes (improved by 200s), our NextJS build times (20-30s improvements), a reduction in the number of circular dependencies (269 to 127), improved bundle chunking and an overall reduction in First Load JS (about 1MB to 840KB or so) for most pages controlled by our codebase.

I'll try checking if I can release the codemod to the general public.

I would recommend getting rid of barrel files if all of the consumers of your code are within the same codebase. If there are consumers of your code outside of your codebase, and you really want those barrel files, have something to generate the barrels as a build artifact to help you avoid the creation of unintended circular dependencies, among other issues, while also providing a nice public api for your code.

@jdfm would you mind sharing your code mod. I am running into the same issue and need to change barrel files to deep file level imports.

@Robbie-Cook
Copy link

When I upgraded to the latest node 14, this issue went away.

@joovnaz
Copy link

joovnaz commented Jul 27, 2021

I have tried with node 14 and next 11.0.1 after some shots (hot reloads) I get the same issue. The project is small with a bunch of pages but many components.

<--- Last few GCs --->

[5288:04386B88]   280004 ms: Scavenge 765.1 (787.9) -> 765.0 (787.9) MB, 1.0 / 0.0 ms  (average mu = 0.449, current mu = 0.000) allocation failure
[5288:04386B88]   280264 ms: Mark-sweep (reduce) 765.0 (787.9) -> 763.0 (787.0) MB, 259.7 / 0.2 ms  (average mu = 0.370, current mu = 0.256) last resort GC in old space requested
[5288:04386B88]   280600 ms: Mark-sweep (reduce) 763.0 (780.0) -> 763.0 (780.3) MB, 336.2 / 0.1 ms  (average mu = 0.207, current mu = 0.000) last resort GC in old space requested


<--- JS stacktrace --->

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
error Command failed with exit code 134.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@joovnaz
Copy link

joovnaz commented Jul 27, 2021

I think this is a critical issue that strongly hinder adoption of Next framework in production environments.

I am a big fan of the framework, so please have a DEEP look into it, after almost 1 year without a fix this deserve a focused investigation and a definitive fix,

@timneutkens
Copy link
Member

@joovnaz please read #15855 (comment) and the many other comments posted that posting heap out of memory messages will not help solve the issue for your particular application. We have had a deep look into this already and made many improvements, unfortunately no reproductions are provided so we can't investigate the particular applications referenced here including yours.

@sokra has made a ton of memory usage improvements to Next.js and webpack (not particularly leaks even, just improvements to how memory is used) which is why most folks have seen significant improvements on Next.js 11 with webpack 5 (see #15855 (comment)). So I'd recommend to ensure you are on the latest version of Next.js and are using webpack 5.

@macrozone
Copy link
Author

I no longer are affected by this problem, but its hard to tell what ultimatly fixed it. We are now on nextjs 11, but already in some version of nextjs 10, the issue was resolved

I observed that once the memory crash in development did no longer ocure, i had instead some fash refresh hicups, where nextjs would force reload the whole page. I cannot tell whether this is related though.

Its important to state that this issue here was never about memory leaks in production. I think this is a completly different problem that might have different reasons.

for those who are affected by memory leaks in production: open up a different issue, please!

Despite the activity here I would suggest to close this issue here. Reason is that a lot has changed since version 9.5.1. and information might be missleading here. Also i am no longer affected, so the initial issue is resolve for me and the information is no longer vaid.

  • if you are still affected by memory leaks / crashses in development: open up a new issue. You can still reference this issue here.
  • if you are affected by memory leaks / crashes in production: also open up a separate issue.

@iamnnort

This comment has been minimized.

@sokra sokra closed this as completed Sep 13, 2021
@rolivegab
Copy link

Tried with next 11.1.2 and node 16.9.0 and have exactly the same problem:

<--- Last few GCs --->

[57:0x7f1dcae51310]   739770 ms: Mark-sweep (reduce) 4073.9 (4143.6) -> 4072.7 (4143.6) MB, 4612.8 / 0.0 ms  (average mu = 0.120, current mu = 0.001) allocation failure scavenge might not succeed
[57:0x7f1dcae51310]   744338 ms: Mark-sweep (reduce) 4074.1 (4143.9) -> 4073.1 (4143.9) MB, 4565.2 / 0.0 ms  (average mu = 0.064, current mu = 0.001) allocation failure scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

@revskill10
Copy link
Contributor

Same issue with latest 12.0.0

@anonymouscatcher
Copy link

Same issue with version 12 on Github actions

@timneutkens
Copy link
Member

timneutkens commented Nov 2, 2021

@revskill10 @alirezavlz your issue is likey related to #30330. Please try upgrading to 12.0.2.

I'm going to lock this issue as there haven't been new reports about the particular issue @macrozone had is resolved.

If you're running into any other issue please create a new issue following the issue template.

@vercel vercel locked as resolved and limited conversation to collaborators Nov 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
please add a complete reproduction Please add a complete reproduction.
Projects
None yet
Development

No branches or pull requests