DayuanJiang/next-ai-draw-io · critical · Error
Server script not found at ${serverPath}. Please ensure the
Error message
Server script not found at ${serverPath}. Please ensure the app was built correctly with 'npm run build'. What it means
startNextServer verifies the standalone Next.js server script exists at serverPath under resourcesPath and throws when the packaged build output is missing.
Source
Thrown at electron/main/next-server.ts:57
await new Promise((resolve) => setTimeout(resolve, 100))
}
throw new Error(`Server startup timeout after ${timeout}ms`)
}
/**
* Start the Next.js standalone server using Electron's utilityProcess
* This API is designed for running Node.js code in the background
*/
export async function startNextServer(): Promise<string> {
const resourcePath = getResourcePath()
const serverPath = path.join(resourcePath, "server.js")
console.log(`Starting Next.js server from: ${resourcePath}`)
console.log(`Server script path: ${serverPath}`)
// Verify server script exists before attempting to start
if (!existsSync(serverPath)) {
throw new Error(
`Server script not found at ${serverPath}. ` +
"Please ensure the app was built correctly with 'npm run build'.",
)
}
// Find an available port (random in production, fixed in development)
const port = await findAvailablePort()
console.log(`Using port: ${port}`)
// Set up environment variables
const env: Record<string, string> = {
NODE_ENV: "production",
PORT: String(port),
HOSTNAME: "127.0.0.1",
// Enable Node.js built-in proxy support for fetch (Node.js 24+)
NODE_USE_ENV_PROXY: "1",
}
View on GitHub (pinned to 155ef4f7ac)
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
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'fs'
if (!existsSync(serverPath)) {
// block startup and prompt rebuild instead of calling startNextServer
} Try / catch
try { await startNextServer() } catch (e) { if ((e as Error).message.includes('not found')) promptRebuildOrReinstall() } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Packaging scripts not including .next/standalone, running the built main process against an unbuilt app, or wrong files config in electron-builder.
Related errors
- Server startup timeout after ${timeout}ms
- Failed to encrypt API key. Cannot securely store credentials
- Invalid preset name
AI-assisted analysis of DayuanJiang/next-ai-draw-io@155ef4f7ac (2026-08-27).
Data as JSON: /api/errors/b3322ed97f78781c.
Report an issue: GitHub.