@@ -552,21 +552,22 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) {
552552, 0 , - 1 ) , mappingKey ) ;
553553} else if ( ArrayIsArray ( target ) ) {
554554if ( target . length === 0 )
555- throw new ERR_INVALID_PACKAGE_TARGET ( StringPrototypeSlice ( baseUrl . pathname
556- , 0 , - 1 ) , mappingKey , subpath , target ) ;
555+ throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
556+ StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey + subpath ) ;
557+ let lastException ;
557558for ( const targetValue of target ) {
558559try {
559560return resolveExportsTarget ( baseUrl , targetValue , subpath , mappingKey ) ;
560561} catch ( e ) {
562+ lastException = e ;
561563if ( e . code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED' &&
562564e . code !== 'ERR_INVALID_PACKAGE_TARGET' )
563565throw e ;
564566}
565567}
566568// Throw last fallback error
567- resolveExportsTarget ( baseUrl , target [ target . length - 1 ] , subpath ,
568- mappingKey ) ;
569- assert ( false ) ;
569+ assert ( lastException !== undefined ) ;
570+ throw lastException ;
570571} else if ( typeof target === 'object' && target !== null ) {
571572const keys = ObjectKeys ( target ) ;
572573if ( keys . some ( isArrayIndex ) ) {
@@ -595,6 +596,9 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) {
595596}
596597throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
597598StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey + subpath ) ;
599+ } else if ( target === null ) {
600+ throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
601+ StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey + subpath ) ;
598602}
599603throw new ERR_INVALID_PACKAGE_TARGET (
600604StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey , subpath , target ) ;
0 commit comments