diff --git a/gofaster/app/src/main/index.js b/gofaster/app/src/main/index.js index f921cda..9259ba9 100644 --- a/gofaster/app/src/main/index.js +++ b/gofaster/app/src/main/index.js @@ -300,8 +300,6 @@ function createWindow() { } originalError.apply(console, args); }; - - `).catch(err => { console.log('JavaScript injection failed:', err.message); // 注入失败不影响应用运行 @@ -361,9 +359,13 @@ function createWindow() { setTimeout(() => { try { const { spawn } = require('child_process'); - const buildProcess = spawn('npm', ['run', 'build:vue'], { + // 使用完整路径来确保能找到npm + const npmPath = process.platform === 'win32' ? 'npm.cmd' : 'npm'; + const buildProcess = spawn(npmPath, ['run', 'build:vue'], { cwd: appRoot, - stdio: 'pipe' + stdio: 'pipe', + shell: true, + env: { ...process.env, PATH: process.env.PATH } }); buildProcess.on('close', (code) => { @@ -374,6 +376,10 @@ function createWindow() { console.error('自动构建失败,请手动运行: npm run dev'); } }); + + buildProcess.on('error', (error) => { + console.error('构建进程启动失败:', error.message); + }); } catch (error) { console.error('启动构建进程失败:', error); }