@@ -548,21 +548,22 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) {
548548 , 0 , - 1 ) , mappingKey ) ;
549549 } else if ( ArrayIsArray ( target ) ) {
550550 if ( target . length === 0 )
551- throw new ERR_INVALID_PACKAGE_TARGET ( StringPrototypeSlice ( baseUrl . pathname
552- , 0 , - 1 ) , mappingKey , subpath , target ) ;
551+ throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
552+ StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey + subpath ) ;
553+ let lastException ;
553554 for ( const targetValue of target ) {
554555 try {
555556 return resolveExportsTarget ( baseUrl , targetValue , subpath , mappingKey ) ;
556557 } catch ( e ) {
558+ lastException = e ;
557559 if ( e . code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED' &&
558560 e . code !== 'ERR_INVALID_PACKAGE_TARGET' )
559561 throw e ;
560562 }
561563 }
562564 // Throw last fallback error
563- resolveExportsTarget ( baseUrl , target [ target . length - 1 ] , subpath ,
564- mappingKey ) ;
565- assert ( false ) ;
565+ assert ( lastException !== undefined ) ;
566+ throw lastException ;
566567 } else if ( typeof target === 'object' && target !== null ) {
567568 const keys = ObjectKeys ( target ) ;
568569 if ( keys . some ( isArrayIndex ) ) {
@@ -591,6 +592,9 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) {
591592 }
592593 throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
593594 StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey + subpath ) ;
595+ } else if ( target === null ) {
596+ throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
597+ StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey + subpath ) ;
594598 }
595599 throw new ERR_INVALID_PACKAGE_TARGET (
596600 StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey , subpath , target ) ;
0 commit comments