@@ -788,13 +788,16 @@ namespace ts {
788788 }
789789
790790 function tryLoadModuleUsingPathsIfEligible ( extensions : Extensions , moduleName : string , loader : ResolutionKindSpecificLoader , state : ModuleResolutionState ) {
791- const { baseUrl, paths } = state . compilerOptions ;
792- if ( baseUrl && paths && ! pathIsRelative ( moduleName ) ) {
791+ const { baseUrl, paths, pathsBasePath } = state . compilerOptions ;
792+ if ( paths && ! pathIsRelative ( moduleName ) ) {
793793 if ( state . traceEnabled ) {
794- trace ( state . host , Diagnostics . baseUrl_option_is_set_to_0_using_this_value_to_resolve_non_relative_module_name_1 , baseUrl , moduleName ) ;
794+ if ( baseUrl ) {
795+ trace ( state . host , Diagnostics . baseUrl_option_is_set_to_0_using_this_value_to_resolve_non_relative_module_name_1 , baseUrl , moduleName ) ;
796+ }
795797 trace ( state . host , Diagnostics . paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0 , moduleName ) ;
796798 }
797- return tryLoadModuleUsingPaths ( extensions , moduleName , baseUrl , paths , loader , /*onlyRecordFailures*/ false , state ) ;
799+ const baseDirectory = baseUrl ?? Debug . checkDefined ( pathsBasePath || state . host . getCurrentDirectory ?.( ) , "Encountered 'paths' without a 'baseUrl', config file, or host 'getCurrentDirectory'." ) ;
800+ return tryLoadModuleUsingPaths ( extensions , moduleName , baseDirectory , paths , loader , /*onlyRecordFailures*/ false , state ) ;
798801 }
799802 }
800803
@@ -1368,6 +1371,7 @@ namespace ts {
13681371 }
13691372 const resolved = forEach ( paths [ matchedPatternText ] , subst => {
13701373 const path = matchedStar ? subst . replace ( "*" , matchedStar ) : subst ;
1374+ // When baseUrl is not specified, the command line parser resolves relative paths to the config file location.
13711375 const candidate = normalizePath ( combinePaths ( baseDirectory , path ) ) ;
13721376 if ( state . traceEnabled ) {
13731377 trace ( state . host , Diagnostics . Trying_substitution_0_candidate_module_location_Colon_1 , subst , path ) ;
0 commit comments