Skip to content

fix(resolve): ignore null export targets#358

Open
kiki-kanri wants to merge 1 commit into
unjs:mainfrom
kiki-kanri:fix/lookup-subpath-null-exports
Open

fix(resolve): ignore null export targets#358
kiki-kanri wants to merge 1 commit into
unjs:mainfrom
kiki-kanri:fix/lookup-subpath-null-exports

Conversation

@kiki-kanri

@kiki-kanri kiki-kanri commented Jun 5, 2026

Copy link
Copy Markdown

Fixes lookupNodeModuleSubpath crashing when a package exports map contains null targets.

null is a valid package exports target for disabling a condition or subpath. Previously _flattenExports recursively processed non-string values, so null targets eventually reached
Object.entries(null) and threw:

TypeError: Cannot convert undefined or null to object

This change treats null export targets as omitted while flattening exports.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of package exports when exports are null, preventing potential errors in export resolution.

Treat null package export targets as omitted when flattening exports for lookupNodeModuleSubpath.
This avoids crashing while reverse-resolving package subpaths that contain condition branches disabled with null.
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 91c543c0-7b31-4d95-a23c-be5ebb3293e1

📥 Commits

Reviewing files that changed from the base of the PR and between beece9b and 27c4c13.

⛔ Files ignored due to path filters (1)
  • test/fixture/package/node_modules/subpaths/package.json is excluded by !**/node_modules/**
📒 Files selected for processing (1)
  • src/resolve.ts

📝 Walkthrough

Walkthrough

Updated the _flattenExports internal helper to accept null exports and return an empty flattened array in that case, improving null-safety without changing behavior for non-null export maps.

Changes

Export flattening robustness

Layer / File(s) Summary
Null-safe export flattening
src/resolve.ts
The _flattenExports function signature now accepts null exports values and immediately returns an empty array when exports is null, while preserving all existing flattening behavior for non-null export maps.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hops through exports with care,
Where null once lurked in the air,
Now a guard clause stands tall and strong,
Making flattening safe all along! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(resolve): ignore null export targets' clearly and specifically summarizes the main change—handling null values in export targets to prevent crashes during module resolution.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant