davidmyersdev / vite-plugin-node-polyfills

A Vite plugin to polyfill Node's Core Modules for browser environments.
MIT License
263 stars 17 forks source link

Plugin breaches heap limit on large projects #35

Closed aryzing closed 6 months ago

aryzing commented 10 months ago

So some good news, and some bad news. Good news: for smaller projects, v0.11.2 does work. The bad news is that for a larger project I'm working on, this plugin is causing the build to fail with a heap limit error,

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
Stack trace ``` 1: 0xc98550 node::Abort() [/home/user/.nvm/versions/node/v20.5.1/bin/node] 2: 0xb700a7 [/home/user/.nvm/versions/node/v20.5.1/bin/node] 3: 0xebae80 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/home/user/.nvm/versions/node/v20.5.1/bin/node] 4: 0xebb167 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/home/user/.nvm/versions/node/v20.5.1/bin/node] 5: 0x10cc7d5 [/home/user/.nvm/versions/node/v20.5.1/bin/node] 6: 0x10e4658 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/home/user/.nvm/versions/node/v20.5.1/bin/node] 7: 0x10ba771 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/home/user/.nvm/versions/node/v20.5.1/bin/node] 8: 0x10bb905 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/home/user/.nvm/versions/node/v20.5.1/bin/node] 9: 0x1098e76 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/home/user/.nvm/versions/node/v20.5.1/bin/node] 10: 0x14f3ca6 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/home/user/.nvm/versions/node/v20.5.1/bin/node] 11: 0x7f93f7ed9ef6 Aborted (core dumped) ```

Possibly useful info:

I've created a new reproduction repo using this plugin on a large codebase which displays the error above during the build.

davidmyersdev commented 6 months ago

@aryzing I believe this is resolved in v0.19.0.

davidmyersdev commented 6 months ago

Adding the original repro as a StackBlitz link: https://stackblitz.com/edit/github-a2ihzd. It doesn't throw an OOM error, but it does slow down significantly and hang at around the same point that it throws locally.

davidmyersdev commented 6 months ago

This is a new repro where it transforms dependencies significantly quicker: https://stackblitz.com/edit/github-a2ihzd-heagzb. It fails at a later step when it tries to launch the Brave browser, but I'm pretty sure that's unrelated.