@@ -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 {
@@ -687,10 +689,11 @@ export function tryNodeResolve(
687
689
// if import can't be found, check if it's an optional peer dep.
688
690
// if so, we can resolve to a special id that errors only when imported.
689
691
if (
692
+ ! options . isHookNodeResolve &&
690
693
basedir !== root && // root has no peer dep
691
- ! isBuiltin ( id ) &&
692
- ! id . includes ( '\0' ) &&
693
- bareImportRE . test ( id )
694
+ ! isBuiltin ( nestedPath ) &&
695
+ ! nestedPath . includes ( '\0' ) &&
696
+ bareImportRE . test ( nestedPath )
694
697
) {
695
698
// find package.json with `name` as main
696
699
const mainPackageJson = lookupFile ( basedir , [ 'package.json' ] , {
@@ -699,11 +702,11 @@ export function tryNodeResolve(
699
702
if ( mainPackageJson ) {
700
703
const mainPkg = JSON . parse ( mainPackageJson )
701
704
if (
702
- mainPkg . peerDependencies ?. [ id ] &&
703
- mainPkg . peerDependenciesMeta ?. [ id ] ?. optional
705
+ mainPkg . peerDependencies ?. [ nestedPath ] &&
706
+ mainPkg . peerDependenciesMeta ?. [ nestedPath ] ?. optional
704
707
) {
705
708
return {
706
- id : `${ optionalPeerDepId } :${ id } :${ mainPkg . name } `
709
+ id : `${ optionalPeerDepId } :${ nestedPath } :${ mainPkg . name } `
707
710
}
708
711
}
709
712
}
0 commit comments