Many files in server assets fails to build the app with error: JavaScript heap out of memory
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Environment
Nuxt project info: 4:49:34 pm
- Operating System: Windows_NT
- Node Version: v20.8.0
- Nuxt Version: 3.7.4
- CLI Version: 3.9.0
- Nitro Version: 2.6.3
- Package Manager: npm@10.1.0
- Builder: -
- User Config: css, devtools, experimental, nitro, modules, postcss, pwa, routeRules, runtimeConfig
- Runtime Modules: @vueuse/nuxt@10.4.1, @bg-dev/nuxt-naiveui@1.4.7, @pinia/nuxt@0.4.11, @pinia-plugin-persistedstate/nuxt@1.1.2, @vite-pwa/nuxt@0.1.1
- Build Modules: -
Reproduction
- I have a Nuxt 3 app.
- I added 3500 JSON files of 300 KB each in
/server/assetsfolder
Describe the bug
No issues in dev (npm run dev). The app starts up properly and runs properly.
But on npm run build, the terminal shows FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory. This error is shown after ℹ Building Nitro Server (preset: node-server).
If I remove these 3500 JSON files, the error is not there. Also, I tried keeping just 1 file; the error goes away. So, the error exists only when there are too many files.
Additional context
This error exists even after trying different presets, i.e., firebase or the default node-server.
I think it would be better to add some wait time after this line so as to not cause memory error.
Logs
✔ Server built in 15417ms 4:28:26 pm
✔ Generated public .output/public nitro 4:28:26 pm
PWA v0.16.5
mode generateSW
precache 86 entries (1942.23 KiB)
files generated
.output\public\sw.js
.output\public\workbox-fa446783.js
ℹ Building Nitro Server (preset: node-server) nitro 4:28:32 pm
<--- Last few GCs --->
[14268:000001B7FCD02090] 191006 ms: Mark-Compact (reduce) 2045.3 (2087.0) -> 2044.6 (2087.0) MB, 481.63 / 0.07 ms (+ 406.2 ms in 97 steps since start of marking, biggest step 20.5 ms, walltime since start of marking 1103 ms) (average mu = 0.651, curren[14268:000001B7FCD02090] 192583 ms: Mark-Compact (reduce) 2046.2 (2087.3) -> 2045.1 (2087.6) MB, 1556.42 / 0.01 ms (average mu = 0.395, current mu = 0.013) allocation failure; scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF6A2303CEF node::SetCppgcReference+15695
2: 00007FF6A227E606 EVP_MD_meth_get_input_blocksize+78566
3: 00007FF6A22803F1 EVP_MD_meth_get_input_blocksize+86225
4: 00007FF6A2CEA191 v8::Isolate::ReportExternalAllocationLimitReached+65
5: 00007FF6A2CD3928 v8::Function::Experimental_IsNopFunction+1336
6: 00007FF6A2B35190 v8::Platform::SystemClockTimeMillis+659552
7: 00007FF6A2B32218 v8::Platform::SystemClockTimeMillis+647400
8: 00007FF6A2B4752A v8::Platform::SystemClockTimeMillis+734202
9: 00007FF6A2B47DA7 v8::Platform::SystemClockTimeMillis+736375
10: 00007FF6A2B566CF v8::Platform::SystemClockTimeMillis+796063
11: 00007FF6A2816C95 v8::CodeEvent::GetFunctionName+116773
12: 00007FF642D5AAF
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/rollup/plugins/server-assets.ts at the linked line and reproduce the failure using npm run build with many files in /server/assets. Compare the build with one file and with the larger set, then confirm that the completed change allows the Nitro node-server build to finish without the JavaScript heap out-of-memory error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, nuxt, typescript
- Domain
- backend, build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 47/100