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.
This commit is contained in:
jackwener committed 2026-03-19 21:05:48 +08:00
1 parent edb21ca67b
commit 6d3e595d36
1 file changed
+7 -4
+7 -4
View File
@@ -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 },