@@ -196,16 +196,21 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre
196196 // Special-case external Node built-ins to be handled via a lazy __require
197197 // helper instead of hoisted ESM imports when strict wrapping is used.
198198 const isExternalWrapped = isWrappedId ( dependencyId , EXTERNAL_SUFFIX ) ;
199- if (
200- parentMeta . initialCommonJSType === IS_WRAPPED_COMMONJS &&
201- ! allowProxy &&
202- isExternalWrapped
203- ) {
199+ let resolvedDependencyId = dependencyId ;
200+ if ( parentMeta . isCommonJS === IS_WRAPPED_COMMONJS && ! allowProxy && isExternalWrapped ) {
204201 const actualExternalId = unwrapId ( dependencyId , EXTERNAL_SUFFIX ) ;
205202 if ( actualExternalId . startsWith ( 'node:' ) ) {
206203 isCommonJS = IS_WRAPPED_COMMONJS ;
207204 parentMeta . isRequiredCommonJS [ dependencyId ] = isCommonJS ;
208205 }
206+ } else if ( isExternalWrapped && ! allowProxy ) {
207+ // If the parent is not wrapped but the dependency is a node: builtin external,
208+ // unwrap the EXTERNAL_SUFFIX so it's treated as a normal external.
209+ // This avoids trying to load the lazy __require proxy for non-wrapped contexts.
210+ const actualExternalId = unwrapId ( dependencyId , EXTERNAL_SUFFIX ) ;
211+ if ( actualExternalId . startsWith ( 'node:' ) ) {
212+ resolvedDependencyId = actualExternalId ;
213+ }
209214 }
210215 const isWrappedCommonJS = isCommonJS === IS_WRAPPED_COMMONJS ;
211216 fullyAnalyzedModules [ dependencyId ] = true ;
@@ -226,8 +231,8 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre
226231 wrappedModuleSideEffects,
227232 source : sources [ index ] . source ,
228233 id : allowProxy
229- ? wrapId ( dependencyId , isWrappedCommonJS ? WRAPPED_SUFFIX : PROXY_SUFFIX )
230- : dependencyId ,
234+ ? wrapId ( resolvedDependencyId , isWrappedCommonJS ? WRAPPED_SUFFIX : PROXY_SUFFIX )
235+ : resolvedDependencyId ,
231236 isCommonJS
232237 } ;
233238 } ) ;
0 commit comments