Error

[Error] heap out of memory

JM_Code 2022. 12. 6. 17:16

프로젝트 배포를 위해 AWS EC2에서 프런트 서버를 실행하는 중 터미널에서 다음과 같은 오류 발생

 

C:\Users\Administrator\bitmovie\src\front>yarn start
yarn run v1.22.19
$ react-scripts start
(node:4276) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:4276) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
Starting the development server...


<--- Last few GCs --->

[4276:000002527953D4B0]   376522 ms: Scavenge 500.8 (517.5) -> 500.2 (518.3) MB, 2.9 / 0.0 ms  (average mu = 0.846, current mu = 0.919) allocation failure;
[4276:000002527953D4B0]   376834 ms: Scavenge 501.8 (518.5) -> 501.2 (523.3) MB, 306.3 / 0.0 ms  (average mu = 0.846, current mu = 0.919) allocation failure;
[4276:000002527953D4B0]   378179 ms: Mark-sweep 503.5 (523.5) -> 501.8 (524.8) MB, 1320.2 / 0.0 ms  (average mu = 0.614, current mu = 0.219) allocation failure; GC in old space requested


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF6B1871B7F node_api_throw_syntax_error+203775
 2: 00007FF6B17F1556 v8::internal::wasm::WasmCode::safepoint_table_offset+63558
 3: 00007FF6B17F28C2 v8::internal::wasm::WasmCode::safepoint_table_offset+68530
 4: 00007FF6B22947F4 v8::Isolate::ReportExternalAllocationLimitReached+116
 5: 00007FF6B227FB52 v8::Isolate::Exit+674
 6: 00007FF6B2101BBC v8::internal::EmbedderStackStateScope::ExplicitScopeForTesting+124
 7: 00007FF6B20FEDDB v8::internal::Heap::CollectGarbage+3963
 8: 00007FF6B2115013 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath+2099
 9: 00007FF6B21158BD v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath+93
10: 00007FF6B211E20A v8::internal::Factory::AllocateRaw+810
11: 00007FF6B2134B2A v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller+90
12: 00007FF6B2134E13 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithMap+35
13: 00007FF6B1EFC153 v8::internal::HashTable<v8::internal::EphemeronHashTable,v8::internal::ObjectHashTableShape>::EnsureCapacity<v8::internal::Isolate>+243
14: 00007FF6B1F144FC v8::internal::ObjectHashTableBase<v8::internal::EphemeronHashTable,v8::internal::ObjectHashTableShape>::Put+460
15: 00007FF6B1F1A12B v8::internal::JSWeakCollection::Set+171
16: 00007FF6B1E207D7 v8::internal::CompilationCache::IsEnabledScriptAndEval+6535
17: 00007FF6B2331E81 v8::internal::SetupIsolateDelegate::SetupHeap+558193
18: 00007FF6B232D60D v8::internal::SetupIsolateDelegate::SetupHeap+539645
19: 00007FF6B232C21D v8::internal::SetupIsolateDelegate::SetupHeap+534541
20: 00007FF632E602D2
error Command failed with exit code 134.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

[해결책 1] 더 큰 메모리 할당

  • 현재용량 확인하는 방법
$ node -e 'console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'
  • 용량 늘리는 방법
$ export NODE_OPTIONS=--max_old_space_size=800

이 두 코드를 터미널 창에 입력해, 용량을 늘린 후 현재 용량을 다시 확인하면 800으로 용량이 늘어나있음을 확인할 수 있다.
(800은 예시일 뿐, 용량 크기는 변경해보면서 적절하게 조절하면 더 좋다.)

매번 서버를 재배포할 때마다 터미널에 위 코드를 입력하는게 번거롭다면, .bashrc 파일에 위의 용량 늘리는 코드를 그대로 추가해도 된다.

 

구글링을 통해 타 블로그에서 위의 방법을 가져와 사용해봤지만 효과가 없음

(EC2의 메모리는 1GB이고 812까지 늘려봄.)

윈도우 가상 메모리 설정으로 가상 메모리를 6GB까지 늘림
-> 위의 방법으로 node 메모리를 4GB까지 늘림
-> 똑같이 에러 발생

 

지금 실력으로는 해결 불가능할 듯.....

'Error' 카테고리의 다른 글

[Error] DOMException  (0) 2022.11.30
[Error] SQLException  (0) 2022.11.29
[Error / Github] 충돌 케이스  (0) 2022.11.28
[Error] MyBatis 오류: Invalid bound statement (not found)  (0) 2022.11.25