@@ -552,21 +552,22 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) {
552552 , 0 , - 1 ) , mappingKey ) ;
553553 } else if ( ArrayIsArray ( target ) ) {
554554 if ( 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 ;
557558 for ( const targetValue of target ) {
558559 try {
559560 return resolveExportsTarget ( baseUrl , targetValue , subpath , mappingKey ) ;
560561 } catch ( e ) {
562+ lastException = e ;
561563 if ( e . code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED' &&
562564 e . code !== 'ERR_INVALID_PACKAGE_TARGET' )
563565 throw 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 ) {
571572 const keys = ObjectKeys ( target ) ;
572573 if ( keys . some ( isArrayIndex ) ) {
@@ -595,6 +596,9 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) {
595596 }
596597 throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
597598 StringPrototypeSlice ( 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 }
599603 throw new ERR_INVALID_PACKAGE_TARGET (
600604 StringPrototypeSlice ( baseUrl . pathname , 0 , - 1 ) , mappingKey , subpath , target ) ;
0 commit comments