From 6d3e595d3665209a783ce4a1ce81065ffb0f2304 Mon Sep 17 00:00:00 2001 From: jackwener Date: Thu, 19 Mar 2026 21:05:13 +0800 Subject: [PATCH] fix: daemon spawn uses --import tsx/esm for dev mode .ts files process.execPath is always plain 'node' even under tsx, so .ts files could not be executed. Use --import tsx/esm flag to enable TypeScript loading in spawned daemon. --- src/browser/mcp.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/browser/mcp.ts b/src/browser/mcp.ts index 4378fec..b97e2c1 100644 --- a/src/browser/mcp.ts +++ b/src/browser/mcp.ts @@ -78,10 +78,13 @@ export class PlaywrightMCP { console.error(`[opencli] Starting daemon (${isTs ? 'ts' : 'js'})...`); } - // Use the current runtime to spawn daemon — avoids slow npx resolution. - // If already running under tsx (dev), process.execPath is tsx's node. - // If running compiled (node dist/), process.execPath is node. - this._daemonProc = spawn(process.execPath, [daemonPath], { + // For compiled .js, use the current node binary directly (fast). + // For .ts dev mode, node can't run .ts files — use tsx via --import. + const spawnArgs = isTs + ? [process.execPath, '--import', 'tsx/esm', daemonPath] + : [process.execPath, daemonPath]; + + this._daemonProc = spawn(spawnArgs[0], spawnArgs.slice(1), { detached: true, stdio: 'ignore', env: { ...process.env },