@@ -105,6 +105,8 @@ export interface InternalResolveOptions extends Required<ResolveOptions> {
105
105
// Resolve using esbuild deps optimization
106
106
getDepsOptimizer ?: ( ssr : boolean ) => DepsOptimizer | undefined
107
107
shouldExternalize ?: ( id : string ) => boolean | undefined
108
+ // Check this resolve is called from `hookNodeResolve` in SSR
109
+ isHookNodeResolve ?: boolean
108
110
}
109
111
110
112
export function resolvePlugin ( resolveOptions : InternalResolveOptions ) : Plugin {
@@ -690,10 +692,11 @@ export function tryNodeResolve(
690
692
// if import can't be found, check if it's an optional peer dep.
691
693
// if so, we can resolve to a special id that errors only when imported.
692
694
if (
695
+ ! options . isHookNodeResolve &&
693
696
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 )
697
700
) {
698
701
// find package.json with `name` as main
699
702
const mainPackageJson = lookupFile ( basedir , [ 'package.json' ] , {
@@ -702,11 +705,11 @@ export function tryNodeResolve(
702
705
if ( mainPackageJson ) {
703
706
const mainPkg = JSON . parse ( mainPackageJson )
704
707
if (
705
- mainPkg . peerDependencies ?. [ id ] &&
706
- mainPkg . peerDependenciesMeta ?. [ id ] ?. optional
708
+ mainPkg . peerDependencies ?. [ nestedPath ] &&
709
+ mainPkg . peerDependenciesMeta ?. [ nestedPath ] ?. optional
707
710
) {
708
711
return {
709
- id : `${ optionalPeerDepId } :${ id } :${ mainPkg . name } `
712
+ id : `${ optionalPeerDepId } :${ nestedPath } :${ mainPkg . name } `
710
713
}
711
714
}
712
715
}
0 commit comments