next.js: long compile times locally - along with "JavaScript heap out of memory" since upgrade to NextJS 13

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.1.0: Sun Oct  9 20:14:30 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8103
    Binaries:
      Node: 18.12.0
      npm: 8.19.3
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.1.7-canary.4
      eslint-config-next: 13.1.6
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue

https://github.com/auction-engine/live

To Reproduce

npm run dev then attempt to navigate to pags using <Link> will take on average 10 seconds.

Describe the Bug

Basically when I develop locally with npm run dev I get long compile times (10s+) [0] and very slow route change times (click a link, wait 10s before route changes.) This all has happened since migrating to the new apps directory with NextJS 13. I also recently had several “JavaScript heap out of memory” crashes [1], all is well with prod.

I have repo in a private repository I’m happy to share access

[0]

wait  - compiling /api/token (client and server)...
event - compiled client and server successfully in 628 ms (4412 modules)
wait  - compiling /user/profile (client and server)...
event - compiled client and server successfully in 398 ms (4446 modules)
wait  - compiling /settings...
event - compiled client and server successfully in 924 ms (4462 modules)
wait  - compiling /admin/page (client and server)...


event - compiled client and server successfully in 20.4s (25650 modules)
wait  - compiling /admin/organizations/[orgid]/auctions/page (client and server)...
event - compiled client and server successfully in 3.5s (25586 modules)

[1]

<--- Last few GCs --->

[6355:0x138078000]   123932 ms: Scavenge (reduce) 4078.2 (4130.8) -> 4077.8 (4130.8) MB, 6.0 / 0.0 ms  (average mu = 0.265, current mu = 0.244) allocation failure;
[6355:0x138078000]   124013 ms: Scavenge (reduce) 4078.4 (4130.8) -> 4078.1 (4130.8) MB, 4.4 / 0.0 ms  (average mu = 0.265, current mu = 0.244) allocation failure;
[6355:0x138078000]   124076 ms: Scavenge (reduce) 4078.7 (4130.8) -> 4078.3 (4130.8) MB, 7.1 / 0.0 ms  (average mu = 0.265, current mu = 0.244) allocation failure;


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x1022b2200 node::Abort() [/usr/local/bin/node]
 2: 0x1022b23f0 node::ModifyCodeGenerationFromStrings(v8::Local<v8::Context>, v8::Local<v8::Value>, bool) [/usr/local/bin/node]
 3: 0x1023f8880 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x1025a35e8 v8::internal::EmbedderStackStateScope::EmbedderStackStateScope(v8::internal::Heap*, v8::internal::EmbedderStackStateScope::Origin, cppgc::EmbedderStackState) [/usr/local/bin/node]
 5: 0x1025a71f0 v8::internal::Heap::CollectSharedGarbage(v8::internal::GarbageCollectionReason) [/usr/local/bin/node]
 6: 0x1025a41e4 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*, v8::GCCallbackFlags) [/usr/local/bin/node]
 7: 0x1025a163c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x1025a0764 v8::internal::Heap::HandleGCRequest() [/usr/local/bin/node]
 9: 0x10254d604 v8::internal::StackGuard::HandleInterrupts() [/usr/local/bin/node]
10: 0x10290c494 v8::internal::Runtime_StackGuardWithGap(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
11: 0x102c5904c Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
12: 0x1075b3518
13: 0x102c29178 Builtins_LoadGlobalIC [/usr/local/bin/node]
14: 0x107b93dd0
15: 0x107b8b620
16: 0x1085360d4
17: 0x108163414
18: 0x10830c654
19: 0x10817327c
20: 0x107ac8c34
21: 0x102c15ef4 Builtins_AsyncFunctionAwaitResolveClosure [/usr/local/bin/node]
22: 0x102ca46f8 Builtins_PromiseFulfillReactionJob [/usr/local/bin/node]
23: 0x102c07c4c Builtins_RunMicrotasks [/usr/local/bin/node]
24: 0x102be23a4 Builtins_JSRunMicrotasksEntry [/usr/local/bin/node]
25: 0x102524e10 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/usr/local/bin/node]
26: 0x102525300 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/usr/local/bin/node]
27: 0x1025254dc v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*, v8::internal::MaybeHandle<v8::internal::Object>*) [/usr/local/bin/node]
28: 0x10254bbac v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [/usr/local/bin/node]
29: 0x10254c444 v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) [/usr/local/bin/node]
30: 0x1021fcc4c node::InternalCallbackScope::Close() [/usr/local/bin/node]
31: 0x1021fcfc8 node::InternalMakeCallback(node::Environment*, v8::Local<v8::Object>, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context) [/usr/local/bin/node]
32: 0x1022118ec node::AsyncWrap::MakeCallback(v8::Local<v8::Function>, int, v8::Local<v8::Value>*) [/usr/local/bin/node]
33: 0x1022b67ac node::fs::FSReqCallback::Reject(v8::Local<v8::Value>) [/usr/local/bin/node]
34: 0x1022b6ecc node::fs::FSReqAfterScope::Reject(uv_fs_s*) [/usr/local/bin/node]
35: 0x1022b7108 node::fs::AfterNoArgs(uv_fs_s*) [/usr/local/bin/node]
36: 0x1022ae7b0 node::MakeLibuvRequestCallback<uv_fs_s, void (*)(uv_fs_s*)>::Wrapper(uv_fs_s*) [/usr/local/bin/node]
37: 0x102bc0cbc uv__work_done [/usr/local/bin/node]
38: 0x102bc4458 uv__async_io [/usr/local/bin/node]
39: 0x102bd61a4 uv__io_poll [/usr/local/bin/node]
40: 0x102bc48e8 uv_run [/usr/local/bin/node]
41: 0x1021fd6d4 node::SpinEventLoop(node::Environment*) [/usr/local/bin/node]
42: 0x1022ed128 node::NodeMainInstance::Run() [/usr/local/bin/node]
43: 0x102280ec8 node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) [/usr/local/bin/node]
44: 0x102281190 node::Start(int, char*

Expected Behavior

Would expect fast load times and navigation as I see in prod and how it was locally prior to NextJS 13.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 6
  • Comments: 22 (6 by maintainers)

Most upvoted comments

can second this, been taking forever to switch routes and 30s compiles out of the blue, can’t seem to find a fix