Skip to content

Conversation

@Scalahansolo
Copy link

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, loadFileNameFromPackageJsonField would return undefined for extensionless paths without attempting to add extensions, even in bundler mode where extensionless imports are supposed to work. This caused imports like:

import { greet } from "@repo/library/utils";

to fail with TS2307: Cannot find module '@repo/library/utils' when the package.json had:

{
  "exports": {
    "./*": "./src/*"
  }
}

Solution

Modified loadFileNameFromPackageJsonField() in src/compiler/moduleNameResolver.ts to add extension probing (.ts, .tsx, .d.ts, .js, .jsx) for extensionless paths when not in ESM mode. This mirrors the existing behavior of loadModuleFromFile() for regular imports.

The fix only affects bundler mode - node16 and nodenext modes continue to require explicit extensions as expected.

Changes

Code Change

  • src/compiler/moduleNameResolver.ts: Added fallback to tryAddingExtensions() for extensionless paths in non-ESM mode

New Tests

  • bundlerWildcardExportsExtensionResolution.ts: Tests that wildcard exports resolve extensionless imports in bundler mode
  • node16WildcardExportsRequiresExtension.ts: Verifies node16 mode still requires extensions (negative test)
  • wildcardExportsBundlerExtensionlessResolution.ts: Fourslash test for quickInfo on resolved imports

Updated Baselines

Several trace baselines updated to reflect the additional extension probing that now occurs for extensionless paths in package.json fields.

@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Dec 18, 2025
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Dec 18, 2025
When using moduleResolution: 'bundler' with wildcard exports patterns like
"./*": "./src/*", extensionless imports (e.g., import from "pkg/utils")
now correctly resolve to TypeScript files (e.g., ./src/utils.ts).

The fix adds extension probing specifically in the exports/imports resolution
path (loadModuleFromTargetExportOrImport) for extensionless paths in bundler
mode, rather than modifying the general loadFileNameFromPackageJsonField
function which would cause duplicate lookups in other code paths.

Fixes microsoft#62909
@Scalahansolo Scalahansolo force-pushed the fix/bundler-wildcard-exports-extensionless-resolution branch from a4294f6 to d7080f7 Compare December 19, 2025 03:13
@Scalahansolo
Copy link
Author

@microsoft-github-policy-service agree company="Linear"

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

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Module resolution: wildcard exports don't work without file extensions when "moduleResolution": "bundler"

2 participants