@@ -105,6 +105,8 @@ export interface InternalResolveOptions extends Required<ResolveOptions> {
105105  // Resolve using esbuild deps optimization 
106106  getDepsOptimizer ?: ( ssr : boolean )  =>  DepsOptimizer  |  undefined 
107107  shouldExternalize ?: ( id : string )  =>  boolean  |  undefined 
108+   // Check this resolve is called from `hookNodeResolve` in SSR 
109+   isHookNodeResolve ?: boolean 
108110} 
109111
110112export  function  resolvePlugin ( resolveOptions : InternalResolveOptions ) : Plugin  { 
@@ -690,10 +692,11 @@ export function tryNodeResolve(
690692    // if import can't be found, check if it's an optional peer dep. 
691693    // if so, we can resolve to a special id that errors only when imported. 
692694    if  ( 
695+       ! options . isHookNodeResolve  && 
693696      basedir  !==  root  &&  // root has no peer dep 
694-       ! isBuiltin ( id )  && 
695-       ! id . includes ( '\0' )  && 
696-       bareImportRE . test ( id ) 
697+       ! isBuiltin ( nestedPath )  && 
698+       ! nestedPath . includes ( '\0' )  && 
699+       bareImportRE . test ( nestedPath ) 
697700    )  { 
698701      // find package.json with `name` as main 
699702      const  mainPackageJson  =  lookupFile ( basedir ,  [ 'package.json' ] ,  { 
@@ -702,11 +705,11 @@ export function tryNodeResolve(
702705      if  ( mainPackageJson )  { 
703706        const  mainPkg  =  JSON . parse ( mainPackageJson ) 
704707        if  ( 
705-           mainPkg . peerDependencies ?. [ id ]  && 
706-           mainPkg . peerDependenciesMeta ?. [ id ] ?. optional 
708+           mainPkg . peerDependencies ?. [ nestedPath ]  && 
709+           mainPkg . peerDependenciesMeta ?. [ nestedPath ] ?. optional 
707710        )  { 
708711          return  { 
709-             id : `${ optionalPeerDepId } ${ id } ${ mainPkg . name }  
712+             id : `${ optionalPeerDepId } ${ nestedPath } ${ mainPkg . name }  
710713          } 
711714        } 
712715      } 
0 commit comments