Skip to content

fix: resolve tsconfig extends via package.json exports field#308156

Open
maruthang wants to merge 1 commit into
microsoft:mainfrom
maruthang:fix/issue-276592-tsconfig-extends-exports
Open

fix: resolve tsconfig extends via package.json exports field#308156
maruthang wants to merge 1 commit into
microsoft:mainfrom
maruthang:fix/issue-276592-tsconfig-extends-exports

Conversation

@maruthang

Copy link
Copy Markdown
Contributor

Fixes #276592

Summary

  • The tsconfig document link provider (cmd+click on "extends" values) now resolves module subpaths through package.json "exports" field mappings
  • Previously, resolveNodeModulesPath() performed naive directory concatenation (e.g., node_modules/@scope/example/base/tsconfig.json) without consulting exports, causing resolution to fail when packages use subpath export remapping
  • Added resolveViaPackageExports() that reads the module's package.json, matches the subpath against export patterns, and resolves the mapped path
  • Supports exact matches (e.g., "./config") and wildcard patterns (e.g., "./*/tsconfig.json" → "./lib/*/tsconfig.json")
  • Handles conditional exports by preferring types > import > require > default
  • Falls back to existing direct path resolution when no exports field exists or no pattern matches

Test plan

  • Create a monorepo with two packages where package A extends tsconfig from package B using exports remapping (see repro repo)
  • Verify cmd+click on the "extends" value navigates to the correct file
  • Verify direct subpath resolution still works for packages without exports
  • Verify conditional exports (object with types/import/default keys) resolve correctly
  • Verify wildcard patterns like "./*/tsconfig.json" map correctly

The document link provider for tsconfig "extends" values now consults
the package.json "exports" field when resolving module subpaths. This
fixes the case where a package remaps subpath exports (e.g.,
"./*/tsconfig.json" -> "./lib/*/tsconfig.json") and VS Code fails to
navigate to the resolved file while tsc resolves it correctly.

Supports exact matches, single-wildcard patterns, and conditional
exports (types > import > require > default). Falls back to direct
path resolution when no exports field or match is found.

Fixes microsoft#276592
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.

typescript language features do not resolve tsconfig extends specifier with package exports subpath remapping

2 participants