fix(cjs-interop): handle function default exports#396
Merged
Conversation
Member
|
Do you mind to add a test fixture? |
59a4568 to
f36aa9f
Compare
Contributor
Author
@pi0 I added a test fixture. Can you check it? |
pi0
reviewed
Sep 15, 2025
pi0
approved these changes
Sep 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
I tried to use knip in Yarn PnP environments with this
vite.config.tsand this error occured:
This error only occurred in Yarn PnP, and did not appear in Yarn with node_modules or in other package managers that resolve module paths through node_modules.
I analyzed the root cause and found that the failure was due to the following reasons:
knip loads config files using jiti internally:
Multiple scenarios cause CJS version selection:
CJS module structure:
jiti's interop logic fails:
Solution
The problem lies in jiti's
interopDefaultProxy logic. When{ default: true }is used, jiti tries to unwrap the default export, but the current logic doesn't handle CJS interop objects properly.Current logic (broken):
Fixed logic:
Result
AS-IS
TO-BE
Reproduce Bug
You can compare the AS-IS and TO-BE examples here: https://github.com/jungwoo3490/repro-jiti-396
1. Clone the repository
2. Move to the
as-isdirectory, install dependencies, and run knip.then you should see the following error log:
3. Move to the
jitidirectory, install dependencies, and build the project.The
jiticode here has already been modified as described above.4. Move to the
to-bedirectory, install dependencies, and run knip:The
to-besetup uses the modified jiti bundle.then you should see the following successful output: