@@ -39,19 +39,32 @@ function ensurePythonShimIfNeeded(env) {
3939 return env ;
4040}
4141
42+ function runNpmExec ( args , { label } ) {
43+ if ( process . env . npm_execpath ) {
44+ const res = spawnSync ( process . execPath , [ process . env . npm_execpath , 'exec' , '--' , ...args ] , {
45+ stdio : 'inherit' ,
46+ env,
47+ } ) ;
48+ return res ;
49+ }
50+ return spawnSync ( 'npm' , [ 'exec' , '--' , ...args ] , { stdio : 'inherit' , env } ) ;
51+ }
52+
4253function runPlaywrightCommand ( args , { label } ) {
4354 if ( process . platform === 'win32' ) {
44- const res = spawnSync ( 'npm' , [ 'exec' , '--' , ... args ] , { stdio : 'inherit' , env } ) ;
55+ const res = runNpmExec ( args , { label } ) ;
4556 if ( res . error && res . error . code === 'ENOENT' ) {
46- console . error ( `[OpenClaw] Failed to run ${ label } : npm not found in PATH` ) ;
57+ console . error (
58+ `[OpenClaw] Failed to run ${ label } : npm not found in PATH (and npm_execpath not set)` ,
59+ ) ;
4760 process . exit ( 1 ) ;
4861 }
4962 return res ;
5063 }
5164
5265 const res = spawnSync ( getNpxCommand ( ) , args , { stdio : 'inherit' , env } ) ;
5366 if ( res . error && res . error . code === 'ENOENT' ) {
54- const fallback = spawnSync ( 'npm' , [ 'exec' , '--' , ... args ] , { stdio : 'inherit' , env } ) ;
67+ const fallback = runNpmExec ( args , { label } ) ;
5568 if ( fallback . error ) {
5669 console . error ( `[OpenClaw] Failed to run ${ label } :` , fallback . error ) ;
5770 process . exit ( 1 ) ;
0 commit comments