vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.48k stars 26.91k forks source link

v8::internal::V8::FatalProcessOutOfMemory during next build #40216

Open kenorb opened 2 years ago

kenorb commented 2 years ago

Verify canary release

Provide environment information

$ node --version
v16.13.1
$ npx next --version
Next.js v12.2.6-canary.8

What browser are you using? (if relevant)

CLI

How are you deploying your application? (if relevant)

next build

Describe the Bug

Next.js crashes during build due to out of memory. The project was building at some point. The recent change which I think of, I've copied ./vendor/drupal/drupal to ./static/drupal/ using copy plugin, so maybe Next.js is trying to scan all those files in static folder and runs out of the memory? If these are static files, why it needs to parse them all? Or maybe it's something else? The project isn't that big, just few files and static files.

Same problem during build in GitHub Actions. Build: 8179674020.

However when running next dev (npm run dev), all seems fine.

Similar issues:

Expected Behavior

Next.js shouldn't crash during build.

Link to reproduction

https://github.com/mycognitive/Drupal7-demo/tree/nextjs-gh-32314

To Reproduce

Repro steps with project using Drupal in wasm:

$ git clone --branch nextjs-gh-32314 https://github.com/mycognitive/Drupal7-demo && cd Drupal7-demo/
$ sudo apt-get install composer # Install Composer if missing.
$ composer install
$ npm ci # or: npm install
$ npm run build
warn  - You have enabled experimental feature (images) in next.config.js.
info  - Linting and checking validity of types  
Webpack version: 5.74.0
info  - Creating an optimized production build .
<--- Last few GCs --->
 marking 5212 ms) (average mu = 0.333, current mu = 0.177) fin[3375343:0x5f0d0c0]    34517 ms: Mark-sweep (reduce) 3794.1 (3888.7) -> 3793.9 (3857.0) MB, 5139.9 / 0.0 ms  (+ 30.4 ms in 62 steps since start of marking, biggest step 1.1 ms, walltime since start of marking 5210 ms) (average mu = 0.218, current mu = 0.1[3375343:0x5f0d0c0]    41479 ms: Mark-sweep (reduce) 4503.0 (4568.3) -> 4119.8 (4185.5) MB, 6275.4 / 0.0 ms  (average mu = 0.153, current mu = 0.099) allocation failure GC in old space requested

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb00d90 node::Abort() [node]
 2: 0xa1823b node::FatalError(char const*, char const*) [node]
 3: 0xcedbce v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xcedf47 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xea6105  [node]
 6: 0xeb57dd v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 7: 0xeb84de v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 8: 0xe7990a v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
 9: 0x11f303c v8::internal::Runtime_AllocateInOldGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
10: 0x15e7819  [node]
Aborted (core dumped)

Increasing to 10GB or more doesn't help either.

$ NODE_OPTIONS="--max-old-space-size=10240" npm run build
...
> next build
...
Webpack version: 5.74.0
info  - Creating an optimized production build ..

#
# Fatal error in , line 0
# Fatal JavaScript invalid size error 169220804
#
#
#
#FailureMessage Object: 0x7ffd73bf1490
 1: 0xb6d311  [node]
 2: 0x1bf5a04 V8_Fatal(char const*, ...) [node]
 3: 0xe74128  [node]
 4: 0x1022832  [node]
 5: 0x10231a9  [node]
 6: 0x11e32b3 v8::internal::Runtime_GrowArrayElements(int, unsigned long*, v8::internal::Isolate*) [node]
 7: 0x15e7819  [node]
Illegal instruction (core dumped)

Stack trace

$ gdb node /var/lib/apport/coredump/core._usr_local_bin_node.1000.a04b6bac-8f93-424b-a07f-d638f5a90698.192997.924828
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=140737348044736) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=140737348044736) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=140737348044736, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007ffff7a75476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff7a5b885 in __GI_abort () at ./stdlib/abort.c:100
#5  0x0000000000b00da1 in node::Abort() ()
#6  0x0000000000a1823b in node::OnFatalError(char const*, char const*) ()
#7  0x0000000000cedbce in v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) ()
#8  0x0000000000cedf47 in v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) ()
#9  0x0000000000ea6105 in v8::internal::Heap::FatalProcessOutOfMemory(char const*) ()
#10 0x0000000000eb57dd in v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) ()
#11 0x0000000000eb84de in v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) ()
#12 0x0000000000e7990a in v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) ()
#13 0x00000000011f2f06 in v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) ()
#14 0x00000000015e7819 in Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit ()
#15 0x00007fffe8a1ab7a in ?? ()
#16 0x0000000000000000 in ?? ()
narendra-dl commented 2 years ago

@kenorb any luck fixing this. I tried updating nextjs to 12.2.0 and node to 14.20.0. Still getting same error