fix: update server startup command to use node from PATH and improve error handling for tsx resolution

This commit is contained in:
Cody Seibert
2025-12-13 15:55:21 -05:00
parent 673dcd1113
commit 574680fc11

View File

@@ -35,12 +35,16 @@ async function startServer() {
let command, args, serverPath; let command, args, serverPath;
if (isDev) { if (isDev) {
// In development, use tsx to run TypeScript directly // In development, use tsx to run TypeScript directly
// Use the node executable that's running Electron // Use node from PATH (process.execPath in Electron points to Electron, not Node.js)
command = process.execPath; // This is the path to node.exe // spawn() resolves "node" from PATH on all platforms (Windows, Linux, macOS)
command = "node";
serverPath = path.join(__dirname, "../../server/src/index.ts"); serverPath = path.join(__dirname, "../../server/src/index.ts");
// Find tsx CLI - check server node_modules first, then root // Find tsx CLI - check server node_modules first, then root
const serverNodeModules = path.join(__dirname, "../../server/node_modules/tsx"); const serverNodeModules = path.join(
__dirname,
"../../server/node_modules/tsx"
);
const rootNodeModules = path.join(__dirname, "../../../node_modules/tsx"); const rootNodeModules = path.join(__dirname, "../../../node_modules/tsx");
let tsxCliPath; let tsxCliPath;
@@ -51,9 +55,13 @@ async function startServer() {
} else { } else {
// Last resort: try require.resolve // Last resort: try require.resolve
try { try {
tsxCliPath = require.resolve("tsx/cli.mjs", { paths: [path.join(__dirname, "../../server")] }); tsxCliPath = require.resolve("tsx/cli.mjs", {
paths: [path.join(__dirname, "../../server")],
});
} catch { } catch {
throw new Error("Could not find tsx. Please run 'npm install' in the server directory."); throw new Error(
"Could not find tsx. Please run 'npm install' in the server directory."
);
} }
} }
@@ -105,13 +113,16 @@ async function waitForServer(maxAttempts = 30) {
for (let i = 0; i < maxAttempts; i++) { for (let i = 0; i < maxAttempts; i++) {
try { try {
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
const req = http.get(`http://localhost:${SERVER_PORT}/api/health`, (res) => { const req = http.get(
if (res.statusCode === 200) { `http://localhost:${SERVER_PORT}/api/health`,
resolve(); (res) => {
} else { if (res.statusCode === 200) {
reject(new Error(`Status: ${res.statusCode}`)); resolve();
} else {
reject(new Error(`Status: ${res.statusCode}`));
}
} }
}); );
req.on("error", reject); req.on("error", reject);
req.setTimeout(1000, () => { req.setTimeout(1000, () => {
req.destroy(); req.destroy();