Description
NOTE - PLEASE READ
This issue has affected a number of people. Please do not comment with comments along the lines of "I'm also hitting this", but add a thumbs up to the issue instead. We know this is an important issue and "me too" comments will only drown out the comments from people attempting to resolve this issue and will be hidden. Please note however that Vite is a community driven project and a fix may need to come from the community
For tips on working around the issue, please see https://rollupjs.org/guide/en/#error-javascript-heap-out-of-memory
Describe the bug
vite build error: out of memory.
Reproduction
https://github.com/Axeldeblen/realworld-big-build
Possible improvements
Reduce magic string memory usage when building source maps: Rich-Harris/magic-string#161 (comment)
Logs (Optional if provided reproduction)
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 00007FF69790ABBD]
Security context: 0x01e6a86408d1
1: decode(aka decode) [000002AD02F874D1] [E:\vite-template\node_modules_rollup@2.40.0@rollup\dist\shared\rollup.js:~133] [pc=0000039464A55451](this=0x037824a004b1 ,0x017863480119 <Very long string[1502653]>)
2: decodedSourcemap(aka decodedSourcemap) [000002AD02F8A979] [E:\vite-template\node_modules_rollup@2.40.0@rollup\dist\shared\roll...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF696CD180F napi_wrap+119407
2: 00007FF696C787E6 v8::internal::OrderedHashTablev8::internal::OrderedHashSet,1::NextTableOffset+38102
3: 00007FF696C795E6 node::OnFatalError+438
4: 00007FF6974B5A6E v8::Isolate::ReportExternalAllocationLimitReached+94
5: 00007FF69749DC21 v8::SharedArrayBuffer::Externalize+833
6: 00007FF69734F3FC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1436
7: 00007FF69735A640 v8::internal::Heap::ProtectUnprotectedMemoryChunks+1312
8: 00007FF697357154 v8::internal::Heap::PageFlagsAreConsistent+3204
9: 00007FF69734C953 v8::internal::Heap::CollectGarbage+1283
10: 00007FF69734AFC4 v8::internal::Heap::AddRetainedMap+2500
11: 00007FF69736C30D v8::internal::Factory::NewFillerObject+61
12: 00007FF6970CF76F v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+1295
13: 00007FF69790ABBD v8::internal::SetupIsolateDelegate::SetupHeap+546925
14: 0000039464A55451
Activity
alexgrozav commentedon Mar 8, 2021
Update It worked when I allocated a whopping 16GB of RAM for Vite's initialization cycle.
As a temporary workaround, you can use the following commands. If it still fails, just increase the size.
Temporary workaround
a. Using command line arguments
b. Using environment variables
I'm getting the same error on https://github.com/inkline/inkline/tree/inkline3 after updating from
2.0.0-beta.60
to2.0.5
, but duringdev
, notbuild
.It looks like a memory leak to me. I've tried starting from a clean project and gradually added my code to it in order to find the issue. I discovered that it only happens when I
rm -r node_modules
,npm install
and thennpm run dev
. If I work on the project with Vite already initialised and cached, it won't happen. I know that because I've started from a clean project 5 times. Every time after I move the files over to the old location and go through the installation, it will crash.I tried increasing the memory allocation size to 9GB, but it didn't do the trick.
Randomly, I also get this error:
danranVm commentedon Mar 9, 2021
fadi-george commentedon Mar 15, 2021
For me at least, Vite was compiling my tests coverage folder which led to this heap error so I had to specify
root: src
in the config. Maybe optimizeDeps could also be set to exclude coverage but I haven't tried it.cpati-kochava commentedon Apr 1, 2021
I could only get it to work with node 15 on an Apple M1 without having to increase the
max_old_space_size
value. Either node 12 or 14 would run out of memory.TheDutchCoder commentedon Apr 15, 2021
It turns out I also had a coverage directory that was the cause of this issue.
I can't seem to set the root to
'src'
, no matter what I try, unless (I guess) I move the index.html file into src?Either way, it would be good to have some sort of exclude option in the Vite config for this.
Edit: I wonder if it's due to there being an
index.html
file in one of those directories and Vite picking that up as if it were an entry point. Might be worth investigating from that angle.Shinigami92 commentedon Apr 16, 2021
samuveth commentedon May 2, 2021
Shinigami92 commentedon May 2, 2021
@samuveth You should workaround this by using
--max-old-space-size=<your-mem -512mb or so>
for now201 remaining items
Kodnot commentedon Apr 6, 2023
In case it helps someone else, what finally worked for us:
All the other various workarounds listed in the comments didn't resolve the issue.
Something that helped debug the issue was building the project in WSL, I couldn't reproduce the issue when running build locally on windows but could do so when building the project through wsl.
VHQDevFS commentedon Apr 7, 2023
Thank your solution.
EfstathiadisD commentedon Apr 7, 2023
andokai commentedon Apr 11, 2023
EfstathiadisD commentedon Apr 11, 2023
IanVS commentedon Apr 11, 2023
@patak-dev I wonder if perhaps this issue should be considered an upstream problem with rollup, and closed here, since there is a lot of noise and I think everything that can be said, has been said. In the end, there's nothing I think Vite can do to solve this issue.
patak-dev commentedon Apr 11, 2023
Even if it is upstream, it is an important issue for a lot of folks so it makes sense to keep tracking it here. I'm afraid people will create new issues if we close this one. Let's keep it open but read-only to avoid generating so many notifications to everybody until it is solved in rollup.
fix: vitejs/vite#2433, build error