{"record":{"id":"caed17f3c50f1856","repo":"thedotmack/claude-mem","slug":"bun-install-failed-in-targetdir-describeexece","errorCode":null,"errorMessage":"bun install failed in ${targetDir}\n${describeExecError(err)}","messagePattern":"bun install failed in (.+?)\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/npx-cli/install/setup-runtime.ts","lineNumber":455,"sourceCode":"  // Async exec (not execSync): a blocked event loop freezes the installer's\n  // clack spinner for the duration of the install, which reads as a stall.\n  const runBunInstall = (): Promise<void> =>\n    new Promise<void>((resolve, reject) => {\n      exec(`${bunCmd} install --frozen-lockfile --ignore-scripts`, {\n        cwd: targetDir,\n        timeout: INSTALL_TIMEOUT_MS,\n        maxBuffer: 16 * 1024 * 1024,\n        ...(IS_WINDOWS ? { shell: process.env.ComSpec ?? 'cmd.exe' } : {}),\n      }, (error, stdout, stderr) =>\n        // exec errors don't carry stdio; attach so describeExecError can report it.\n        error ? reject(Object.assign(error, { stdout, stderr })) : resolve());\n    });\n\n  try {\n    await runBunInstall();\n  } catch (error) {\n    const err = error instanceof Error ? error : new Error(String(error));\n    throw new Error(`bun install failed in ${targetDir}\\n${describeExecError(err)}`);\n  }\n\n  verifyCriticalModules(targetDir);\n}\n\nexport function readInstallMarker(targetDir: string): MarkerSchema | null {\n  const path = markerPath(targetDir);\n  if (!existsSync(path)) return null;\n  const content = readFileSync(path, 'utf-8');\n  try {\n    const marker = JSON.parse(content);\n    if (marker && typeof marker === 'object' && typeof marker.version === 'string') {\n      return marker as MarkerSchema;\n    }\n  } catch {\n    // Legacy installs wrote only the version string as plain text.\n  }\n","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/npx-cli/install/setup-runtime.ts#L437-L473","documentation":"Thrown by installPluginDependencies() during the npx-cli bootstrap when the underlying `bun install --frozen-lockfile --ignore-scripts` child process exits non-zero, times out, or crashes. The error message is built with describeExecError(), which attaches the exec stdout/stderr that Bun produced (explicitly Object.assigned onto the rejection at setup-runtime.ts:448) so the root cause is visible. This is the last-resort surface for any failure in plugin dependency installation.","triggerScenarios":"Running `bun install --frozen-lockfile` against a targetDir whose bun.lockb is out of sync with package.json (frozen-lockfile rejects drift); no network/offline registry access; INSTALL_TIMEOUT_MS exceeded by a slow registry or a hung tree-sitter-swift nested postinstall; on Windows, a bunPath containing spaces when shell quoting fails; maxBuffer (16MB) exceeded by noisy install output.","commonSituations":"A developer edits package.json and forgets to regenerate bun.lockb, so --frozen-lockfile aborts. CI runs in an air-gapped environment with no registry mirror. A corporate proxy intercepts the registry and returns HTML. Bun is the wrong version (older than the lockfile format). A path with spaces on Windows without the cmd.exe shell fallback.","solutions":["Read the describeExecError output embedded in the message — the attached stdout/stderr names the exact dependency or Bun error code (e.g. ELIFECYCLE, lockfile mismatch).","If the lockfile drifted, regenerate it locally with `bun install` (no --frozen-lockfile) and commit the updated bun.lockb before re-running.","If network-related, verify registry reachability (`bun install` in the targetDir manually), check HTTPS_PROXY/registry config, and clear Bun's cache (`bun pm cache rm`).","If it timed out, retry on a faster network; if a known-slow postinstall is the cause, confirm --ignore-scripts is in effect (it is by default here).","On Windows with a spaced bunPath, ensure the cmd.exe shell branch at line 445 is taken (ComSpec is set) or move Bun to a space-free path."],"exampleFix":"// before: lockfile drift causes frozen install to fail\n// regenerate the lockfile locally, then commit\n$ cd plugin && bun install\n$ git add bun.lockb && git commit -m \"chore: refresh lockfile\"\n\n// before (Windows, spaced path fails): bunPath = \"C:\\Program Files\\bun.exe\"\n// after: install Bun to a space-free location or rely on the shell fallback\n$ set ComSpec=C:\\Windows\\System32\\cmd.exe","handlingStrategy":"try-catch","validationCode":"import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\n\n// Run before calling installPluginDependencies\nfunction preflightInstall(targetDir: string, bunPath: string): void {\n  if (!existsSync(join(targetDir, 'package.json'))) {\n    throw new Error(`no package.json at ${targetDir}`);\n  }\n  if (!existsSync(bunPath)) {\n    throw new Error(`bun not found at ${bunPath}`);\n  }\n  if (!existsSync(join(targetDir, 'bun.lockb')) && !existsSync(join(targetDir, 'bun.lock'))) {\n    console.warn('warning: no lockfile; --frozen-lockfile will fail unless one exists');\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await installPluginDependencies(targetDir, bunPath);\n} catch (error) {\n  // The thrown Error embeds describeExecError output (stdout/stderr attached).\n  const msg = error instanceof Error ? error.message : String(error);\n  if (/lockfile|frozen/i.test(msg)) {\n    // drift: regenerate, then retry once\n  } else if (/ETIMEDOUT|timeout/i.test(msg)) {\n    // network/timeout: retry with backoff\n  } else {\n    throw error; // surface unknown causes\n  }\n}","preventionTips":["Always regenerate bun.lockb after editing package.json so --frozen-lockfile succeeds.","Pin a Bun version and verify it on PATH in CI before invoking the installer.","Run installs on a network with registry access; configure HTTPS_PROXY/registry mirrors for air-gapped CI.","On Windows, install Bun in a space-free path or ensure ComSpec points at cmd.exe."],"tags":["install","bun","network","windows","exec"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}