fix: stack overflow when config have both default and named exports #49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
🧩 Backstory
After the 7.4.0 update, a
Maximum call stack size exceedederror started to occur when usingtaze, that started throwing errors with configurations that export both default and named exports simultaneously.🐛 Issue
After some debugging, I traced the issue back to this change, which introduced the faulty behavior. As I understand,
interopDefaultfunction tries to create a getter for the self-referentialdefaultkey and/or for the module property which already is the default object. This results in defining a self-referential getter (defaultValue.default→mod.default→defaultValue), which leads to infinite recursion when Node attempts to inspect or log the object, ultimately triggering the stack overflow.✔️ Fix
This PR prevents processing the
defaultkey or the module property which already is the default object when defining forwarded getters. By skipping these, we avoid creating a self-referential properties and eliminate the infinite recursion.🧪 Tests
All existing tests have passed.
Also, I’ve added several new tests covering the main scenarios that previously triggered the recursion.
🧾 Reproduction
unconfig-reproAdditional context
I’m not deeply familiar with the internal design of
unconfigand its ecosystem, so the approach may not be ideal.Feedback and further refinements are very welcome.