From 525fa5ef8f2e3722c56615306e4e70df8d14f14c Mon Sep 17 00:00:00 2001 From: cocos02 Date: Mon, 15 Jun 2026 11:42:31 +0800 Subject: [PATCH] fix: add shell:true to spawn calls for cross-platform npx compatibility --- vite.config.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index 2c7522e..eb809a6 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -63,6 +63,7 @@ function apiSavePlugin() { const child = spawn('npx', args, { env: { ...process.env, DEEPSEEK_API_KEY: apiKey || process.env.DEEPSEEK_API_KEY || '' }, timeout: 15000, + shell: true, }) let stdout = '' @@ -71,11 +72,11 @@ function apiSavePlugin() { child.stdout.on('data', (d: Buffer) => stdout += d.toString()) child.stderr.on('data', (d: Buffer) => stderr += d.toString()) - child.on('error', () => { + child.on('error', (err: any) => { if (responded) return responded = true res.writeHead(503) - res.end(JSON.stringify({ error: 'opencode 未安装,请运行 npm install' })) + res.end(JSON.stringify({ error: err?.message || 'spawn failed' })) }) child.on('close', async (code) => { @@ -93,6 +94,7 @@ function apiSavePlugin() { const listChild = spawn('npx', ['opencode', 'session', 'list', '--format', 'json', '--max-count', '1'], { timeout: 5000, env: { ...process.env, DEEPSEEK_API_KEY: apiKey || process.env.DEEPSEEK_API_KEY || '' }, + shell: true, }) let listOut = '' listChild.stdout.on('data', (d: Buffer) => listOut += d.toString()) @@ -134,7 +136,7 @@ function apiSavePlugin() { server.middlewares.use('/api/ai/sessions', (req: any, res: any) => { if (req.method !== 'GET') { res.writeHead(405); res.end(); return } try { - const child = spawn('npx', ['opencode', 'session', 'list', '--format', 'json'], { timeout: 5000 }) + const child = spawn('npx', ['opencode', 'session', 'list', '--format', 'json'], { timeout: 5000, shell: true }) let stdout = '' let responded = false child.stdout.on('data', (d: Buffer) => stdout += d.toString())