Troubleshooting Digital Garden
related document: Obsidian Digital Garden, 2025-01-11 obsidian 블로그 개편플랜
Javascript heap out of memory 💣#
2000여개의 문서를 한 번에 퍼블리시 하자 Vercel쪽에서 다음과 같은 에러를 뿜어냈다. 레포지토리를 클론하여 로컬에서 npm run build
해도 같은 결과가 나왔다:
<--- Last few GCs --->
[81745:0x138030000] 385240 ms: Scavenge (reduce) (interleaved) 3883.6 (3901.3) -> 3883.6 (3900.3) MB, pooled: 0 MB, 4.46 / 0.00 ms (average mu = 0.279, current mu = 0.251) external memory pressure;
[81745:0x138030000] 386000 ms: Mark-Compact (reduce) 3883.6 (3900.3) -> 3778.5 (3794.6) MB, pooled: 0 MB, 759.12 / 0.00 ms (+ 1.4 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 772 ms) (average mu = 0.318, cu
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----
1: 0x102c0866c node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
2: 0x102db0740 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
3: 0x102f6d6f0 v8::internal::Heap::CallGCPrologueCallbacks(v8::GCType, v8::GCCallbackFlags, v8::internal::GCTracer::Scope::ScopeId) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
4: 0x102f73188 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags)::$_1::operator()() const [/opt/homebrew/Cellar/node/23.6.0/bin/node]
5: 0x102f6da34 void heap::base::Stack::SetMarkerAndCallbackImpl<v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags)::$_1>(heap::base::Stack*, void*, void const*) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
6: 0x102b20028 PushAllRegistersAndIterateStack [/opt/homebrew/Cellar/node/23.6.0/bin/node]
7: 0x102f6a91c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
8: 0x102f64364 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
9: 0x102f64d2c v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
10: 0x102f51004 v8::internal::MaybeHandle<v8::internal::SeqTwoByteString> v8::internal::FactoryBase<v8::internal::Factory>::NewRawStringWithMap<v8::internal::SeqTwoByteString>(int, v8::internal::Tagged<v8::internal::Map>, v8::internal::AllocationType) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
11: 0x103174378 v8::internal::String::SlowFlatten(v8::internal::Isolate*, v8::internal::Handle<v8::internal::ConsString>, v8::internal::AllocationType) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
12: 0x102dc8680 v8::String::Utf8Length(v8::Isolate*) const [/opt/homebrew/Cellar/node/23.6.0/bin/node]
13: 0x102bd8c7c node::Buffer::(anonymous namespace)::SlowByteLengthUtf8(v8::FunctionCallbackInfo<v8::Value> const&) [/opt/homebrew/Cellar/node/23.
6.0/bin/node]
14: 0x10296aaac Builtins_CallApiCallbackOptimizedNoProfiling [/opt/homebrew/Cellar/node/23.6.0/bin/node]
15: 0x10b3b1abc
16: 0x10c0bc3ac
17: 0x10bed2d4c
18: 0x10ba449a0
19: 0x10b3cb304
20: 0x10c04c340
21: 0x102a70ff0 Builtins_PromiseConstructor [/opt/homebrew/Cellar/node/23.6.0/bin/node]
22: 0x102965838 Builtins_JSBuiltinsConstructStub [/opt/homebrew/Cellar/node/23.6.0/bin/node]
23: 0x10c098f20
24: 0x1029a5e20 Builtins_AsyncFunctionAwaitResolveClosure [/opt/homebrew/Cellar/node/23.6.0/bin/node]
25: 0x102a73298 Builtins_PromiseFulfillReactionJob [/opt/homebrew/Cellar/node/23.6.0/bin/node]
26: 0x102995214 Builtins_RunMicrotasks [/opt/homebrew/Cellar/node/23.6.0/bin/node]
27: 0x1029663f0 Builtins_JSRunMicrotasksEntry [/opt/homebrew/Cellar/node/23.6.0/bin/node]
28: 0x102ee25dc v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
29: 0x102ee2d48 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParamsconst&) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
30: 0x102f0d2fc v8::internal::MicrotaskQueue::PerformCheckpointInternal(v8::Isolate*) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
31: 0x102b215e4 node::InternalCallbackScope::Close() [/opt/homebrew/Cellar/node/23.6.0/bin/node]
32: 0x102b21b94 node::InternalMakeCallback(node::Environment*, v8::Local<v8::Object>, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context, v8::Local<v8::Value>) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
33: 0x102b39c9c node::AsyncWrap::MakeCallback(v8::Local<v8::Function>, int, v8::Local<v8::Value>*) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
34: 0x102c0e8e4 node::fs::FSReqCallback::Resolve(v8::Local<v8::Value>) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
35: 0x102c10c04 node::fs::AfterMkdirp(uv_fs_s*) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
36: 0x102bfeef0 node::MakeLibuvRequestCallback<uv_fs_s, void (*)(uv_fs_s*)>::Wrapper(uv_fs_s*) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
37: 0x102c12da0 node::fs::MKDirpAsync(uv_loop_s*, uv_fs_s*, char const*, int, void (*)(uv_fs_s*))::$_0::__invoke(uv_fs_s*) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
38: 0x10627e5f0 uv__work_done [/opt/homebrew/Cellar/libuv/1.49.2/lib/libuv.1.dylib]
39: 0x106281c9c uv__async_io [/opt/homebrew/Cellar/libuv/1.49.2/lib/libuv.1.dylib]
40: 0x106292110 uv__io_poll [/opt/homebrew/Cellar/libuv/1.49.2/lib/libuv.1.dylib]
41: 0x106282130 uv_run [/opt/homebrew/Cellar/libuv/1.49.2/lib/libuv.1.dylib]
42: 0x102b22488 node::SpinEventLoopInternal(node::Environment*) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
43: 0x102c4fdac node::NodeMainInstance::Run(node::ExitCode*, node::Environment*) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
44: 0x102c4fb00 node::NodeMainInstance::Run() [/opt/homebrew/Cellar/node/23.6.0/bin/node]
45: 0x102bc889c node::Start(int, char**) [/opt/homebrew/Cellar/node/23.6.0/bin/node]
46: 0x18cea8274 start [/usr/lib/dyld]
ERROR: "build:eleventy" exited with 1.
Problem Solved?#
github.com > Issues > Javascript Out of Memory Heap Error when 1,900+ Posts Added #695 대화에서 나와 똑같은 문제를 겪은 사람을 보았다. 아주 엘레강트한(?) 해결방법이.. Node.JS의 힙 메모리 용량을 늘려줄 뿐이었다
node --max-old-space-size=6000 ./node_modules/@11ty/eleventy/cmd.js --quiet
그래서 나는 package.json의 scripts.build.eleventy
키에 NODE_OPTIONS
가 있길래 아래와 같이 추가해두었다.
{
"scripts": {
"build:eleventy": "cross-env ELEVENTY_ENV=prod NODE_OPTIONS=--max-old-space-size=8192 eleventy",
},
}
그랬더니 로컬에서 정상적으로 빌드가 된다! Vercel에서도 잘 되는지 확인해보자. 아마 공짜 컴퓨팅이라서 시간은 더 오래 걸리겠지만 메모리 부족 문제만 겪지 않으면 된다.