---
type: note
kind: Troubleshooting
tags: ['astro', 'node', 'memory']
status: release
ctime: 2024-04-21
mtime: 2024-06-06
generated: { by: human:cbcruk, at: 2024-06-07T22:33:39Z }
verified: { by: claude/opus-5, at: 2026-08-19T00:00:00Z }
sources:
  - id: astro
    resource: https://astro.build/
    title: "Astro"
  - id: nodejs-docs-latest-v20
    resource: https://nodejs.org/docs/latest-v20.x/api/cli.html#--max-old-space-sizesize-in-megabytes
    title: "`NODE_OPTIONS=--max_old_space_size`(in megabytes)"
  - id: docs-astro-en-guides
    resource: https://docs.astro.build/en/guides/imports/#astroglob
    title: "`Astro.glob`"
  - id: stevefenton-co-blog-2023
    resource: https://www.stevefenton.co.uk/blog/2023/07/astro-javascript-heap-out-of-memory/
---

[Astro](https://astro.build/)를 사용한 프로젝트에서 빌드를 하는데 _JavaScript heap out of memory_ 에러가 발생했다.
쉽게 해결하자면 [`NODE_OPTIONS=--max_old_space_size`(in megabytes)](https://nodejs.org/docs/latest-v20.x/api/cli.html#--max-old-space-sizesize-in-megabytes) 설정해서 우회할수는 있겠지만 정리가 필요해서 메모를 남겨본다.
일단 원인은 파일사이즈가 크다는 점, 그리고 카테고리(국가)별 데이터가 많다는 점인데 개선할만한 부분은 두가지 정도인 듯.

- 가능한 전처리해서 데이터를 다시 생성해서 참조
- [`Astro.glob`](https://docs.astro.build/en/guides/imports/#astroglob)을 사용해서 조건부로 데이터를 가져오기

예상치 못한 에러였는데 역시 트레이드오프는 존재하기 마련이다.

---

- https://www.stevefenton.co.uk/blog/2023/07/astro-javascript-heap-out-of-memory/
