@@ -116,7 +116,9 @@ class CodeInjector implements ICodeInjector {
116
116
envOverrides ?: { [ key : string ] : string }
117
117
} ) {
118
118
const nodeBinary = process . execPath ; // Path to the Node.js binary running this script
119
- const npmPath = path . join ( path . dirname ( nodeBinary ) , 'npm' ) ; // Path to the npm executable
119
+ // On Windows, npm is npm.cmd, on Unix systems it's npm
120
+ const npmExecutable = process . platform === 'win32' ? 'npm.cmd' : 'npm' ;
121
+ const npmPath = path . join ( path . dirname ( nodeBinary ) , npmExecutable ) ; // Path to the npm executable
120
122
const env = {
121
123
VITE_ADMINFORTH_PUBLIC_PATH : this . adminforth . config . baseUrl ,
122
124
FORCE_COLOR : '1' ,
@@ -127,7 +129,12 @@ class CodeInjector implements ICodeInjector {
127
129
console . log ( `⚙️ exec: npm ${ command } ` ) ;
128
130
process . env . HEAVY_DEBUG && console . log ( `🪲 npm ${ command } cwd:` , cwd ) ;
129
131
process . env . HEAVY_DEBUG && console . time ( `npm ${ command } done in` ) ;
130
- const { stdout : out , stderr : err } = await execAsync ( `${ nodeBinary } ${ npmPath } ${ command } ` , {
132
+
133
+ // Quote paths that contain spaces (especially important on Windows)
134
+ const quotedNodeBinary = nodeBinary . includes ( ' ' ) ? `"${ nodeBinary } "` : nodeBinary ;
135
+ const quotedNpmPath = npmPath . includes ( ' ' ) ? `"${ npmPath } "` : npmPath ;
136
+
137
+ const { stdout : out , stderr : err } = await execAsync ( `${ quotedNodeBinary } ${ quotedNpmPath } ${ command } ` , {
131
138
cwd,
132
139
env,
133
140
} ) ;
@@ -872,17 +879,17 @@ class CodeInjector implements ICodeInjector {
872
879
const command = 'run dev' ;
873
880
console . log ( `⚙️ spawn: npm ${ command } ...` ) ;
874
881
const nodeBinary = process . execPath ;
875
- const npmPath = path . join ( path . dirname ( nodeBinary ) , 'npm' ) ;
882
+ // On Windows, npm is npm.cmd, on Unix systems it's npm
883
+ const npmExecutable = process . platform === 'win32' ? 'npm.cmd' : 'npm' ;
884
+ const npmPath = path . join ( path . dirname ( nodeBinary ) , npmExecutable ) ;
876
885
const env = {
877
886
VITE_ADMINFORTH_PUBLIC_PATH : this . adminforth . config . baseUrl ,
878
887
FORCE_COLOR : '1' ,
879
888
...process . env ,
880
889
} ;
881
890
882
- const devServer = spawn ( `${ nodeBinary } ` , [ `${ npmPath } ` , ...command . split ( ' ' ) ] , {
883
- cwd,
884
- env,
885
- } ) ;
891
+ // Execute npm directly (npm.cmd on Windows, npm on Unix)
892
+ const devServer = spawn ( npmPath , command . split ( ' ' ) , { cwd, env } ) ;
886
893
devServer . stdout . on ( 'data' , ( data ) => {
887
894
if ( data . includes ( '➜' ) ) {
888
895
// TODO: maybe better use our string "App port: 5174. HMR port: 5274", it is more reliable because vue might change their output
0 commit comments