{"record":{"id":"8639f56b6d4ab57c","repo":"can1357/oh-my-pi","slug":"failed-to-install-runtime-at-runtimedir-with","errorCode":null,"errorMessage":"Failed to install runtime at ${runtimeDir} with ${process.execPath} install (exit ${exitCode}): ${output}","messagePattern":"Failed to install runtime at (.+?) with (.+?) install \\(exit (.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/utils/src/runtime-install.ts","lineNumber":398,"sourceCode":"\treturn new Response(stream).text();\n}\n\nasync function runRuntimeInstall(runtimeDir: string): Promise<void> {\n\t// `process.execPath` is plain bun in source/bundle mode and the compiled\n\t// binary otherwise; BUN_BE_BUN makes the compiled binary act as bun.\n\tconst proc = Bun.spawn([process.execPath, \"install\", \"--cwd\", runtimeDir, \"--production\"], {\n\t\tenv: { ...Bun.env, BUN_BE_BUN: \"1\" },\n\t\tstdout: \"pipe\",\n\t\tstderr: \"pipe\",\n\t});\n\tconst [stdout, stderr, exitCode] = await Promise.all([\n\t\treadPipe(proc.stdout as ReadableStream<Uint8Array> | null),\n\t\treadPipe(proc.stderr as ReadableStream<Uint8Array> | null),\n\t\tproc.exited,\n\t]);\n\tif (exitCode === 0) return;\n\tconst output = `${stdout}\\n${stderr}`.trim();\n\tthrow new Error(\n\t\t`Failed to install runtime at ${runtimeDir} with ${process.execPath} install (exit ${exitCode}): ${output}`,\n\t);\n}\n\n/**\n * Materialize a pinned dependency set into `runtimeDir` (idempotent,\n * cross-process safe). Returns `runtimeDir`.\n *\n * Serialization uses the OS-backed {@link withFileLock} at\n * `${runtimeDir}.install.lock`, which the kernel releases on process death, so\n * a crashed installer cannot wedge later attempts (issue #10120). The path is\n * deliberately distinct from the legacy `${runtimeDir}.lock` mkdir directory;\n * {@link withLegacyInstallLock} atomically reserves that namespace during the\n * new install so older processes cannot cross the migration boundary.\n */\nexport async function ensureRuntimeInstalled(options: EnsureRuntimeInstalledOptions): Promise<string> {\n\tconst { runtimeDir, install, onPhase, lockAttempts = 240, lockSleepMs = 250 } = options;\n\tlet probePackage = options.probePackage;","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/runtime-install.ts#L380-L416","documentation":"ensureRuntimeInstalled drives `<execPath> install` to materialize a pinned dependency set into a runtime directory. If the install subprocess exits non-zero, this error wraps the exit code and combined stdout+stderr output so the caller can see why runtime installation failed.","triggerScenarios":"The spawned `process.execPath install` command exits with a non-zero code — bad network during package download, invalid/broken package.json in the runtime dir, registry auth failures, or unsupported install flags on the current runtime version.","commonSituations":"Offline or proxied CI environments, private npm registries requiring auth, corrupted runtime cache directories, version drift where the runtime binary no longer supports the install invocation.","solutions":["Read the `output` portion of the message — it contains the installer's own error.","Delete the runtimeDir cache and retry to clear a corrupted install state.","Check network/registry access and credentials (NPM_TOKEN, .npmrc).","Pin/verify the runtime version supports the install command used."],"exampleFix":"// before (stale/corrupt cache)\nawait ensureRuntimeInstalled(dir, manifest);\n// after\nawait fs.rm(dir, { recursive: true, force: true });\nawait ensureRuntimeInstalled(dir, manifest);","handlingStrategy":"retry","validationCode":"const probe = Bun.file(path.join(runtimeDir, 'node_modules', firstDep, 'package.json'));\nif (!(await probe.exists())) {\n  // will need install; verify network/registry reachability first\n}","typeGuard":null,"tryCatchPattern":"try {\n  await ensureRuntimeInstalled(dir, manifest);\n} catch (err) {\n  if (String(err.message).includes('Failed to install runtime')) {\n    await fs.rm(dir, { recursive: true, force: true });\n    await ensureRuntimeInstalled(dir, manifest); // one clean retry\n  } else throw err;\n}","preventionTips":["Verify registry credentials (.npmrc, NPM_TOKEN) in CI before install.","Clear the runtime cache directory on version bumps of the manifest.","Capture and surface the installer output on failure for faster diagnosis."],"tags":["install","subprocess","npm"],"backgroundTag":"package-install-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}