fix: use npx instead of process.execPath for backend subprocess
This commit is contained in:
1 parent
80e9363ba5
commit
8515ab471b
1 file changed
+6
-8
+6
-8
@@ -23,20 +23,18 @@ function createIcon(size = 32): Electron.NativeImage {
|
||||
let backend: ChildProcess | null = null
|
||||
|
||||
function startBackend(): void {
|
||||
const tsx = path.join(PROJECT_DIR, 'node_modules', 'tsx', 'dist', 'cli.mjs')
|
||||
const node = process.execPath // Use Electron's bundled Node.js
|
||||
broadcastLog('[后端] 正在启动...')
|
||||
|
||||
backend = spawn(node, [tsx, 'src/index.ts'], {
|
||||
backend = spawn('npx', ['tsx', 'src/index.ts'], {
|
||||
cwd: PROJECT_DIR,
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
env: {
|
||||
...process.env,
|
||||
PORT: '3000',
|
||||
SKIP_PLC: '1',
|
||||
},
|
||||
env: { ...process.env, PORT: '3000', SKIP_PLC: '1' },
|
||||
shell: process.platform === 'win32', // Windows 需要 shell 运行 .cmd 文件
|
||||
windowsHide: true,
|
||||
})
|
||||
|
||||
backend.on('error', (err) => broadcastLog(`[后端] 启动失败: ${err.message}`))
|
||||
|
||||
backend.stdout?.on('data', (d: Buffer) => {
|
||||
for (const line of d.toString().split('\n').filter(Boolean)) broadcastLog(line)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user