vercel / ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
https://npmjs.com/@vercel/ncc
MIT License
9.13k stars 287 forks source link

Memory leak during build with ncc - conditional properties #653

Open Marcinthedev opened 3 years ago

Marcinthedev commented 3 years ago

We are using ncc for a big project amd while migrating to typescript error with memory leak occured during project building with ncc. That might be related to settings (maybe?) of ncc, but while returning conditional properties - memory leak is popping up. Example: Let's say we return object with many conditional properties:

... 
return {
    ...(conditionalProp1 && {conditionalProp1}),
    ... //etc.
}

Then during building it crashes at actually nothing helps. Have anyone had similar issue? The "walkaround" solution for it is to create a function which omits all of the empty/falsy properties and then it works normally.

guybedford commented 3 years ago

Hi @Marcinthedev, can you clarify what you mean by the conditional properties here, do you have an exact code example or pointer to which part of the processing you believe is blowing up in your case?

Marcinthedev commented 3 years ago

Just as I mentioned in the code. I have objects that their properties are set or not depending on whether value is falsy or not. If I use it in lots of places in the code then during the build I have memory leak.

const someObject = {
  ...(prop1 && {prop1}),
...etc.
}