{"record":{"id":"31f0352fcec07492","repo":"larksuite/cli","slug":"npm-not-found-in-path-w","errorCode":null,"errorMessage":"npm not found in PATH: %w","messagePattern":"npm not found in PATH: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/selfupdate/updater.go","lineNumber":243,"sourceCode":"\t\tif part == \".pnpm\" {\n\t\t\treturn true\n\t\t}\n\t\tif part == \"pnpm\" && i+1 < len(parts) && parts[i+1] == \"store\" {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n// 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)","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/selfupdate/updater.go#L225-L261","documentation":"RunNpmInstall updates the CLI by running `npm install -g <package>@<version>`. Before spawning the process it resolves npm via exec.LookPath; if npm is not on PATH the error wraps the LookPath failure and is stored in NpmResult.Err instead of being returned directly.","triggerScenarios":"Calling RunNpmInstall (self-update flow) on a machine where the npm executable is not installed, or exists only in a directory not on the current PATH (e.g. installed via nvm but PATH not loaded in non-interactive shells).","commonSituations":"Node.js installed but npm missing/broken; nvm/fnm managed Node not active in cron/CI/non-login shells; minimal containers without Node; PATH stripped under sudo.","solutions":["Install Node.js/npm or verify with `npm --version` in the same shell","Add the npm bin directory to PATH (e.g. `export PATH=\"$HOME/.nvm/versions/node/vX/bin:$PATH\"` for nvm)","Prefer the built-in update path if available, or reinstall manually (npm i -g <package>@<version>) once npm is on PATH","Check NpmResult.Err (not a returned error) — the updater surfaces this wrapped cause"],"exampleFix":"// before\n$ lark update  # npm not found in PATH: exec: \"npm\": executable file not found in $PATH\n// after\nexport PATH=\"$HOME/.nvm/versions/node/v20/bin:$PATH\"\n$ lark update","handlingStrategy":"fallback","validationCode":"if _, err := exec.LookPath(\"npm\"); err != nil {\n\treturn fmt.Errorf(\"npm is required for self-update; install Node.js or add npm to PATH\")\n}","typeGuard":null,"tryCatchPattern":"res := updater.RunNpmInstall(version)\nif res.Err != nil {\n\tvar execErr *exec.Error\n\tif errors.As(res.Err, &execErr) || strings.Contains(res.Err.Error(), \"not found in PATH\") {\n\t\t// fall back to manual update instructions instead of retrying\n\t}\n\treturn res.Err\n}","preventionTips":["Verify `npm --version` works in the same environment that runs the CLI","For nvm/fnm users, ensure PATH is set in non-interactive shells (cron, CI)","Install Node.js in containers that run the CLI","Remember the error is delivered via NpmResult.Err, not a returned error — always check it"],"tags":["npm","path","selfupdate","environment"],"backgroundTag":"command-not-found-on-path","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"}