{"record":{"id":"b3322ed97f78781c","repo":"DayuanJiang/next-ai-draw-io","slug":"server-script-not-found-at-serverpath-please-e","errorCode":null,"errorMessage":"Server script not found at ${serverPath}. Please ensure the app was built correctly with 'npm run build'.","messagePattern":"Server script not found at (.+?)\\. Please ensure the app was built correctly with 'npm run build'\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"electron/main/next-server.ts","lineNumber":57,"sourceCode":"        await new Promise((resolve) => setTimeout(resolve, 100))\n    }\n    throw new Error(`Server startup timeout after ${timeout}ms`)\n}\n\n/**\n * Start the Next.js standalone server using Electron's utilityProcess\n * This API is designed for running Node.js code in the background\n */\nexport async function startNextServer(): Promise<string> {\n    const resourcePath = getResourcePath()\n    const serverPath = path.join(resourcePath, \"server.js\")\n\n    console.log(`Starting Next.js server from: ${resourcePath}`)\n    console.log(`Server script path: ${serverPath}`)\n\n    // Verify server script exists before attempting to start\n    if (!existsSync(serverPath)) {\n        throw new Error(\n            `Server script not found at ${serverPath}. ` +\n                \"Please ensure the app was built correctly with 'npm run build'.\",\n        )\n    }\n\n    // Find an available port (random in production, fixed in development)\n    const port = await findAvailablePort()\n    console.log(`Using port: ${port}`)\n\n    // Set up environment variables\n    const env: Record<string, string> = {\n        NODE_ENV: \"production\",\n        PORT: String(port),\n        HOSTNAME: \"127.0.0.1\",\n        // Enable Node.js built-in proxy support for fetch (Node.js 24+)\n        NODE_USE_ENV_PROXY: \"1\",\n    }\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/DayuanJiang/next-ai-draw-io/blob/155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1/electron/main/next-server.ts#L39-L75","documentation":"startNextServer verifies the standalone Next.js server script exists at serverPath under resourcesPath and throws when the packaged build output is missing.","triggerScenarios":"Launching the Electron app in production when the Next.js standalone server bundle was never copied into resources, or running without having executed npm run build in dev.","commonSituations":"Packaging scripts not including .next/standalone, running the built main process against an unbuilt app, or wrong files config in electron-builder.","solutions":["Run npm run build before starting/packaging","Verify serverPath printed in the log exists; copy .next/standalone into the app resources per the build config","Fix electron-builder 'files'/'extraResources' so the standalone server ships with the app","In dev, ensure resourcePath resolves to the project's standalone output"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { existsSync } from 'fs'\nif (!existsSync(serverPath)) {\n  // block startup and prompt rebuild instead of calling startNextServer\n}","typeGuard":null,"tryCatchPattern":"try { await startNextServer() } catch (e) { if ((e as Error).message.includes('not found')) promptRebuildOrReinstall() }","preventionTips":["Verify .next/standalone is included in electron-builder extraResources","Add a CI packaging step that asserts the server script exists","Never ship a package without a post-build existence check"],"tags":["electron","nextjs","packaging","build"],"backgroundTag":"missing-build-artifact","analyzedSha":"155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1","analyzedAt":"2026-08-27T11:40:38.297Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}