{"record":{"id":"f55f2289ab868721","repo":"paperclipai/paperclip","slug":"failed-to-prepare-workspace-build-artifacts-before","errorCode":null,"errorMessage":"Failed to prepare workspace build artifacts before starting the Paperclip dev server.\\n${formatError(result.error)}","messagePattern":"Failed to prepare workspace build artifacts before starting the Paperclip dev server\\.\\\\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/commands/run.ts","lineNumber":173,"sourceCode":"  if (process.env.PAPERCLIP_UI_DEV_MIDDLEWARE !== undefined) return;\n  const normalized = entrypoint.replaceAll(\"\\\\\", \"/\");\n  if (normalized.endsWith(\"/server/src/index.ts\") || normalized.endsWith(\"@paperclipai/server/src/index.ts\")) {\n    process.env.PAPERCLIP_UI_DEV_MIDDLEWARE = \"true\";\n  }\n}\n\nfunction ensureDevWorkspaceBuildDeps(projectRoot: string): void {\n  const buildScript = path.resolve(projectRoot, \"scripts/ensure-plugin-build-deps.mjs\");\n  if (!fs.existsSync(buildScript)) return;\n\n  const result = spawnSync(process.execPath, [buildScript], {\n    cwd: projectRoot,\n    stdio: \"inherit\",\n    timeout: 120_000,\n  });\n\n  if (result.error) {\n    throw new Error(\n      `Failed to prepare workspace build artifacts before starting the Paperclip dev server.\\n${formatError(result.error)}`,\n    );\n  }\n\n  if ((result.status ?? 1) !== 0) {\n    throw new Error(\n      \"Failed to prepare workspace build artifacts before starting the Paperclip dev server.\",\n    );\n  }\n}\n\nasync function importServerEntry(): Promise<StartedServer> {\n  // Dev mode: try local workspace path (monorepo with tsx)\n  const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), \"../../..\");\n  const devEntry = path.resolve(projectRoot, \"server/src/index.ts\");\n  if (fs.existsSync(devEntry)) {\n    ensureDevWorkspaceBuildDeps(projectRoot);\n    maybeEnableUiDevMiddleware(devEntry);","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/run.ts#L155-L191","documentation":"Thrown by ensureDevWorkspaceBuildDeps() when spawnSync itself fails to launch the `scripts/ensure-plugin-build-deps.mjs` script (result.error set). This is a spawn-level failure (ENOENT, EACCES, timeout-abort), distinct from the script exiting non-zero. It runs only in dev workspace mode where `server/src/index.ts` exists.","triggerScenarios":"Running `paperclipai run` (or dev server boot) inside the monorepo when spawnSync fails to exec `process.execPath scripts/ensure-plugin-build-deps.mjs`. Producers: node binary not resolvable via process.execPath, script missing or not executable, EACCES, or the spawn hit the 120s timeout and was aborted (result.error set on timeout-kill in some Node versions).","commonSituations":"Broken Node install, file permission errors on the script, an interrupted dev boot that left a half-built state, or a slow plugin build exceeding the 120s timeout.","solutions":["Read the formatted error in the message — ENOENT points to node or the script; EACCES to permissions.","Run the script manually to see the real failure: `node scripts/ensure-plugin-build-deps.mjs`.","If it is a timeout, profile the plugin build deps script and speed it up or raise resources.","Reinstall workspace deps: `pnpm install`."],"exampleFix":"# before: dev boot fails with spawn error\npaperclipai run\n# after: run the script directly to surface the cause\nnode scripts/ensure-plugin-build-deps.mjs","handlingStrategy":"try-catch","validationCode":"import { spawnSync } from 'node:child_process';\nimport fs from 'node:fs';\nfunction precheckBuildScript(projectRoot: string): void {\n  const script = `${projectRoot}/scripts/ensure-plugin-build-deps.mjs`;\n  if (!fs.existsSync(script)) return;\n  if (!fs.existsSync(process.execPath)) throw new Error(`Node not found at ${process.execPath}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  ensureDevWorkspaceBuildDeps(projectRoot);\n} catch (err) {\n  console.error('Build-deps prep failed; run manually:', err);\n  throw err;\n}","preventionTips":["Run the build-deps script manually first when iterating in dev to surface failures early.","Keep Node and the script path stable across dev machines."],"tags":["dev","build","spawn","workspace","run"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}