From fe84e0d7489b8cc8a7bc94f7cd3699bcfb3c2a91 Mon Sep 17 00:00:00 2001 From: Alberto Arena Date: Tue, 4 Aug 2026 18:06:11 +0200 Subject: [PATCH] build: raise Node heap for production build The production build renders thousands of modules and exceeds V8's default heap ceiling, so `npm run build` fails with a JavaScript heap out-of-memory error during "rendering chunks". Set NODE_OPTIONS=--max-old-space-size=8192 on the Vite build step via cross-env (kept portable for Windows), so a fresh clone builds without any manual environment setup. Document the matching Docker memory requirement in DOCKER.md, since the container build hits the same limit when the Docker VM has too little RAM. --- DOCKER.md | 8 ++++++++ package-lock.json | 20 ++++++++++++++++++++ package.json | 3 ++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/DOCKER.md b/DOCKER.md index 404505e..75d10e3 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -103,6 +103,14 @@ RUN npm config set strict-ssl false && npm install This is necessary in some build environments with certificate validation issues. +### Out of Memory During Build + +The production build is memory-intensive (the app compiles thousands of modules). If `docker compose up` or `docker build` fails with an out-of-memory error such as `Reached heap limit` or `cannot allocate memory` during the `npm run build` step, increase the memory available to Docker: + +- **Docker Desktop**: Settings, then Resources, then Memory. Set it to at least **6-8 GB** and apply. + +The Dockerfile raises the Node heap (`NODE_OPTIONS=--max-old-space-size`) for the build. That heap size must fit inside the memory available to Docker, so raising the Docker memory limit is the fix when the build runs out of memory. + ### Container Not Starting Check the logs: diff --git a/package-lock.json b/package-lock.json index 2e2e1eb..86ad547 100644 --- a/package-lock.json +++ b/package-lock.json @@ -86,6 +86,7 @@ "@typescript-eslint/parser": "8.11.0", "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "10.4.19", + "cross-env": "^7.0.3", "esbuild": "^0.28.0", "eslint": "^8.57.0", "eslint-config-prettier": "9.1.0", @@ -8363,6 +8364,25 @@ "integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==", "license": "MIT" }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", diff --git a/package.json b/package.json index 0fff4de..b3ff9af 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "vite", - "build": "tsc && vite build", + "build": "tsc && cross-env NODE_OPTIONS=--max-old-space-size=8192 vite build", "lint": "eslint -c .eslintrc.json ./src/**/**/*.{ts,tsx} --fix", "preview": "vite preview" }, @@ -88,6 +88,7 @@ "@typescript-eslint/parser": "8.11.0", "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "10.4.19", + "cross-env": "^7.0.3", "esbuild": "^0.28.0", "eslint": "^8.57.0", "eslint-config-prettier": "9.1.0",