@@ -210,11 +210,18 @@ export function createEsmAndCjsTests(
210210 // Create a minimal package.json with requested dependencies (if any) and install them
211211 const additionalDependencies = options ?. additionalDependencies ?? { } ;
212212 if ( Object . keys ( additionalDependencies ) . length > 0 ) {
213+ // Ensure Volta picks up the monorepo's pinned Node/Yarn versions even inside the tmp dir.
214+ // Combined with the explicit `volta run yarn add` below, this guarantees we use the repo's toolchain.
215+ // This avoids CI engine mismatches (e.g. packages requiring Node >= 20 while the system Node is 18).
216+ const monorepoRootPackageJsonPath = join ( process . cwd ( ) , '../../package.json' ) ;
213217 const packageJson = {
214218 name : 'tmp-integration-test' ,
215219 private : true ,
216220 version : '0.0.0' ,
217221 dependencies : additionalDependencies ,
222+ volta : {
223+ extends : monorepoRootPackageJsonPath ,
224+ } ,
218225 } as const ;
219226
220227 writeFileSync ( join ( tmpDirPath , 'package.json' ) , JSON . stringify ( packageJson , null , 2 ) ) ;
@@ -228,7 +235,15 @@ export function createEsmAndCjsTests(
228235 } ) ;
229236
230237 if ( deps . length > 0 ) {
231- const result = spawnSync ( 'yarn' , [ 'add' , '--non-interactive' , ...deps ] , {
238+ // Install using Volta when available to enforce the monorepo's pinned Node/Yarn versions.
239+ // Falls back to direct yarn if Volta is not on PATH (e.g. local dev without Volta).
240+ const hasVolta = spawnSync ( 'volta' , [ '--version' ] , { encoding : 'utf8' } ) . status === 0 ;
241+ const cmd = hasVolta ? 'volta' : 'yarn' ;
242+ const args = hasVolta
243+ ? [ 'run' , 'yarn' , 'add' , '--non-interactive' , ...deps ]
244+ : [ 'add' , '--non-interactive' , ...deps ] ;
245+
246+ const result = spawnSync ( cmd , args , {
232247 cwd : tmpDirPath ,
233248 encoding : 'utf8' ,
234249 } ) ;
@@ -237,9 +252,9 @@ export function createEsmAndCjsTests(
237252 // eslint-disable-next-line no-console
238253 console . log ( '[additionalDependencies]' , deps . join ( ' ' ) ) ;
239254 // eslint-disable-next-line no-console
240- console . log ( '[yarn stdout]' , result . stdout ) ;
255+ console . log ( `[ ${ cmd } stdout]` , result . stdout ) ;
241256 // eslint-disable-next-line no-console
242- console . log ( '[yarn stderr]' , result . stderr ) ;
257+ console . log ( `[ ${ cmd } stderr]` , result . stderr ) ;
243258 }
244259
245260 if ( result . error ) {
0 commit comments