@@ -788,13 +788,16 @@ namespace ts {
788
788
}
789
789
790
790
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 ) ) {
793
793
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
+ }
795
797
trace ( state . host , Diagnostics . paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0 , moduleName ) ;
796
798
}
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 ) ;
798
801
}
799
802
}
800
803
@@ -1368,6 +1371,7 @@ namespace ts {
1368
1371
}
1369
1372
const resolved = forEach ( paths [ matchedPatternText ] , subst => {
1370
1373
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.
1371
1375
const candidate = normalizePath ( combinePaths ( baseDirectory , path ) ) ;
1372
1376
if ( state . traceEnabled ) {
1373
1377
trace ( state . host , Diagnostics . Trying_substitution_0_candidate_module_location_Colon_1 , subst , path ) ;
0 commit comments