@@ -553,21 +553,22 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) {
553553 , 0 , - 1 ) , mappingKey ) ;
554554 } else if ( ArrayIsArray ( target ) ) {
555555 if ( target . length === 0 )
556- throw new ERR_INVALID_PACKAGE_TARGET ( StringPrototypeSlice ( baseUrl . pathname
557- , 0 , - 1 ) , mappingKey , subpath , target ) ;
556+ throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
557+ StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey + subpath ) ;
558+ let lastException ;
558559 for ( const targetValue of target ) {
559560 try {
560561 return resolveExportsTarget ( baseUrl , targetValue , subpath , mappingKey ) ;
561562 } catch ( e ) {
563+ lastException = e ;
562564 if ( e . code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED' &&
563565 e . code !== 'ERR_INVALID_PACKAGE_TARGET' )
564566 throw e ;
565567 }
566568 }
567569 // Throw last fallback error
568- resolveExportsTarget ( baseUrl , target [ target . length - 1 ] , subpath ,
569- mappingKey ) ;
570- assert ( false ) ;
570+ assert ( lastException !== undefined ) ;
571+ throw lastException ;
571572 } else if ( typeof target === 'object' && target !== null ) {
572573 const keys = ObjectKeys ( target ) ;
573574 if ( keys . some ( isArrayIndex ) ) {
@@ -596,6 +597,9 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) {
596597 }
597598 throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
598599 StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey + subpath ) ;
600+ } else if ( target === null ) {
601+ throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
602+ StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey + subpath ) ;
599603 }
600604 throw new ERR_INVALID_PACKAGE_TARGET (
601605 StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey , subpath , target ) ;
0 commit comments