{"record":{"id":"549fa8d7a32afe59","repo":"larksuite/cli","slug":"npm-install-timed-out-after-s","errorCode":null,"errorMessage":"npm install timed out after %s","messagePattern":"npm install timed out after (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/selfupdate/updater.go","lineNumber":253,"sourceCode":"// RunNpmInstall executes npm install -g @larksuite/cli@<version>.\nfunc (u *Updater) RunNpmInstall(version string) *NpmResult {\n\tif u.NpmInstallOverride != nil {\n\t\treturn u.NpmInstallOverride(version)\n\t}\n\tr := &NpmResult{}\n\tnpmPath, err := exec.LookPath(\"npm\")\n\tif err != nil {\n\t\tr.Err = fmt.Errorf(\"npm not found in PATH: %w\", err)\n\t\treturn r\n\t}\n\tctx, cancel := context.WithTimeout(context.Background(), npmInstallTimeout)\n\tdefer cancel()\n\tcmd := exec.CommandContext(ctx, npmPath, \"install\", \"-g\", NpmPackage+\"@\"+version)\n\tcmd.Stdout = &r.Stdout\n\tcmd.Stderr = &r.Stderr\n\tr.Err = cmd.Run()\n\tif ctx.Err() == context.DeadlineExceeded {\n\t\tr.Err = fmt.Errorf(\"npm install timed out after %s\", npmInstallTimeout)\n\t}\n\treturn r\n}\n\n// RunPnpmInstall executes pnpm add -g @larksuite/cli@<version>.\nfunc (u *Updater) RunPnpmInstall(version string) *NpmResult {\n\tif u.PnpmInstallOverride != nil {\n\t\treturn u.PnpmInstallOverride(version)\n\t}\n\tr := &NpmResult{}\n\tpnpmPath, err := exec.LookPath(\"pnpm\")\n\tif err != nil {\n\t\tr.Err = fmt.Errorf(\"pnpm not found in PATH: %w\", err)\n\t\treturn r\n\t}\n\tctx, cancel := context.WithTimeout(context.Background(), npmInstallTimeout)\n\tdefer cancel()\n\tcmd := exec.CommandContext(ctx, pnpmPath, \"add\", \"-g\", NpmPackage+\"@\"+version)","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/selfupdate/updater.go#L235-L271","documentation":"RunNpmInstall runs `npm install -g @larksuite/cli@<version>` under a context with a fixed timeout (npmInstallTimeout). If cmd.Run() has not returned before the deadline, the context is canceled and the code replaces the underlying error with this message, reporting that npm install exceeded the allowed time.","triggerScenarios":"Calling Updater.RunNpmInstall(version) during a self-update when the spawned `npm install -g @larksuite/cli@<version>` process runs longer than npmInstallTimeout, causing context.DeadlineExceeded on the exec context.","commonSituations":"Slow or saturated network when downloading the package from the npm registry; large install tree; npm cache corruption forcing re-download; corporate proxy or mirror latency; running on a slow CI runner or constrained machine.","solutions":["Check network connectivity and npm registry reachability (npm ping), then retry the update","Clear or repair the npm cache (`npm cache verify` or `npm cache clean --force`) and retry","Use a faster registry mirror via `npm config set registry <mirror>` if the default registry is slow","If installs legitimately need longer, update the binary manually with `npm install -g @larksuite/cli@latest` outside the CLI's timeout"],"exampleFix":"// before\nres := updater.RunNpmInstall(\"1.2.3\")\nif res.Err != nil { log.Fatal(res.Err) }\n// after\nres := updater.RunNpmInstall(\"1.2.3\")\nif res.Err != nil {\n\tif strings.Contains(res.Err.Error(), \"timed out\") {\n\t\t// fall back to manual install or retry with better network\n\t\tlog.Printf(\"npm install timed out; retry or install manually: %v\", res.Err)\n\t} else {\n\t\tlog.Fatal(res.Err)\n\t}\n}","handlingStrategy":"try-catch","validationCode":"if _, err := exec.LookPath(\"npm\"); err != nil { /* fix PATH first */ }\nout, err := exec.Command(\"npm\", \"ping\").CombinedOutput() // check registry reachability before updating","typeGuard":null,"tryCatchPattern":"res := updater.RunNpmInstall(version)\nif res.Err != nil {\n\tif strings.Contains(res.Err.Error(), \"timed out after\") {\n\t\t// timeout path: retry or manual install\n\t} else {\n\t\treturn res.Err\n\t}\n}","preventionTips":["Ensure a stable network connection before self-updating","Pre-warm the npm cache with `npm view @larksuite/cli version` before installing","Prefer wired/fast networks on CI runners for global installs","Know the fixed npmInstallTimeout and install manually if your environment cannot meet it"],"tags":["npm","timeout","selfupdate","network"],"backgroundTag":"process-execution-timeout","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}