Fix wildcard exports extensionless resolution in bundler mode #62911
+470
−1
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.
Summary
Fixes #62909
When using
moduleResolution: "bundler"with wildcard exports patterns like"./*": "./src/*", extensionless imports (e.g.,import from "@repo/library/utils") now correctly resolve to TypeScript files (e.g.,./src/utils.ts).Problem
Previously,
loadFileNameFromPackageJsonFieldwould returnundefinedfor extensionless paths without attempting to add extensions, even in bundler mode where extensionless imports are supposed to work. This caused imports like:to fail with
TS2307: Cannot find module '@repo/library/utils'when the package.json had:{ "exports": { "./*": "./src/*" } }Solution
Modified
loadFileNameFromPackageJsonField()insrc/compiler/moduleNameResolver.tsto add extension probing (.ts,.tsx,.d.ts,.js,.jsx) for extensionless paths when not in ESM mode. This mirrors the existing behavior ofloadModuleFromFile()for regular imports.The fix only affects bundler mode -
node16andnodenextmodes continue to require explicit extensions as expected.Changes
Code Change
src/compiler/moduleNameResolver.ts: Added fallback totryAddingExtensions()for extensionless paths in non-ESM modeNew Tests
bundlerWildcardExportsExtensionResolution.ts: Tests that wildcard exports resolve extensionless imports in bundler modenode16WildcardExportsRequiresExtension.ts: Verifies node16 mode still requires extensions (negative test)wildcardExportsBundlerExtensionlessResolution.ts: Fourslash test for quickInfo on resolved importsUpdated Baselines
Several trace baselines updated to reflect the additional extension probing that now occurs for extensionless paths in package.json fields.