{"record":{"id":"6c4588e2e5967472","repo":"can1357/oh-my-pi","slug":"npm-install-failed-with-exit-code-result-exitcod","errorCode":null,"errorMessage":"npm install failed with exit code ${result.exitCode}","messagePattern":"npm install failed with exit code (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli/update-cli.ts","lineNumber":1549,"sourceCode":"\t\tif (pruneResult && pruneResult.removedEntries > 0) {\n\t\t\tconsole.log(chalk.dim(`Pruned ${pruneResult.removedEntries} stale Bun cache entries`));\n\t\t}\n\t} catch (err) {\n\t\tconsole.log(chalk.yellow(`Warning: could not prune stale Bun cache entries: ${err}`));\n\t}\n\treturn verification;\n}\n\nasync function updateViaNpm(release: ReleaseInfo): Promise<InstalledVersionVerification | undefined> {\n\tconsole.log(chalk.dim(\"Updating via npm...\"));\n\tif (release.packages.pkg !== PACKAGE) {\n\t\tawait migrateRenamedInstall(release, packageManagerMigrationSteps(\"npm\", release));\n\t\treturn undefined;\n\t}\n\tconst args = buildNpmInstallArgs(release.version, currentNativeTag(), release.packages);\n\tconst result = await $`npm ${args}`.nothrow();\n\tif (result.exitCode !== 0) {\n\t\tthrow new Error(`npm install failed with exit code ${result.exitCode}`);\n\t}\n\n\treturn await verifyInstalledVersion(release.version);\n}\n/** Injectable steps for {@link updateViaManager}; mirrors {@link RenameMigrationSteps}. */\nexport interface ManagerUpdateSteps {\n\t/** Manager name used in progress and recovery messages. */\n\tmanager: string;\n\t/**\n\t * Run the manager's global install. Resolves to the PATH-resolved launcher\n\t * check, or `undefined` when a rename migration already verified and\n\t * reported its own result.\n\t */\n\tinstall(): Promise<InstalledVersionVerification | undefined>;\n\t/** Re-check the PATH-resolved launcher after the install threw. */\n\tverify(): Promise<InstalledVersionVerification>;\n\t/** Take `launcherPath` over with the standalone release binary. */\n\trepair(launcherPath: string): Promise<void>;","sourceCodeStart":1531,"sourceCodeEnd":1567,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli/update-cli.ts#L1531-L1567","documentation":"Thrown when the self-update flow installs via npm (`npm install -g ...`) and the npm process exits non-zero. Like the bun variant, npm's diagnostic output is swallowed; only the exit code is reported. It indicates the target version could not be installed globally with npm.","triggerScenarios":"Running self-update on an npm-managed install when `npm <install args>` fails — registry unreachable (EACCES on the global node_modules prefix, 404 for the version, network timeout, or npm not on PATH is caught earlier).","commonSituations":"npm global prefix requires sudo (common with system Node installs); corporate proxy/registry mirror missing the package version; npm cache corruption; disk full.","solutions":["Run the equivalent `npm install -g <pkg>@<version>` manually to see npm's actual error","Fix npm prefix permissions (use a user-owned prefix via nvm/volta, or `npm config set prefix`)","Verify registry access and that the version exists (`npm view <pkg>@<version>`)","Clear the npm cache (`npm cache clean --force`) if EINTEGRY/corruption errors appear","Update via a different method (bun, brew, or the standalone binary installer)"],"exampleFix":"// before\nconst result = await $`npm ${args}`.nothrow();\nif (result.exitCode !== 0) {\n\tthrow new Error(`npm install failed with exit code ${result.exitCode}`);\n}\n// after\nconst result = await $`npm ${args}`.nothrow();\nif (result.exitCode !== 0) {\n\tthrow new Error(`npm install failed with exit code ${result.exitCode}: ${result.stderr.text()}`);\n}","handlingStrategy":"try-catch","validationCode":"const probe = await $`npm ping`.nothrow();\nif (probe.exitCode !== 0) throw new Error(\"npm registry unreachable; fix network before update\");","typeGuard":"function npmInstallSucceeded(r: { exitCode: number }): r is { exitCode: 0 } {\n\treturn r.exitCode === 0;\n}","tryCatchPattern":"try {\n\tawait updateSelf();\n} catch (err) {\n\tif (err.message.startsWith(\"npm install failed\")) {\n\t\t// check npm prefix perms / registry, rerun `npm install -g <pkg>@<ver>` manually\n\t} else throw err;\n}","preventionTips":["Use a user-owned npm prefix (nvm/volta) to avoid EACCES on global installs","Confirm the target version exists with `npm view <pkg>@<version>` before scripted updates","Clear a suspect npm cache before release-train updates"],"tags":["install","npm","self-update","process-exit-code"],"backgroundTag":"package-install-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}