larksuite/cli · error
npm not found in PATH: %w
Error message
npm not found in PATH: %w
What it means
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.
Source
Thrown at internal/selfupdate/updater.go:243
if part == ".pnpm" {
return true
}
if part == "pnpm" && i+1 < len(parts) && parts[i+1] == "store" {
return true
}
}
return false
}
// RunNpmInstall executes npm install -g @larksuite/cli@<version>.
func (u *Updater) RunNpmInstall(version string) *NpmResult {
if u.NpmInstallOverride != nil {
return u.NpmInstallOverride(version)
}
r := &NpmResult{}
npmPath, err := exec.LookPath("npm")
if err != nil {
r.Err = fmt.Errorf("npm not found in PATH: %w", err)
return r
}
ctx, cancel := context.WithTimeout(context.Background(), npmInstallTimeout)
defer cancel()
cmd := exec.CommandContext(ctx, npmPath, "install", "-g", NpmPackage+"@"+version)
cmd.Stdout = &r.Stdout
cmd.Stderr = &r.Stderr
r.Err = cmd.Run()
if ctx.Err() == context.DeadlineExceeded {
r.Err = fmt.Errorf("npm install timed out after %s", npmInstallTimeout)
}
return r
}
// RunPnpmInstall executes pnpm add -g @larksuite/cli@<version>.
func (u *Updater) RunPnpmInstall(version string) *NpmResult {
if u.PnpmInstallOverride != nil {
return u.PnpmInstallOverride(version)View on GitHub (pinned to 7fd6ef3c07)
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
Example fix
// before $ lark update # npm not found in PATH: exec: "npm": executable file not found in $PATH // after export PATH="$HOME/.nvm/versions/node/v20/bin:$PATH" $ lark update
Defensive patterns
Strategy: fallback
Validate before calling
if _, err := exec.LookPath("npm"); err != nil {
return fmt.Errorf("npm is required for self-update; install Node.js or add npm to PATH")
} Try / catch
res := updater.RunNpmInstall(version)
if res.Err != nil {
var execErr *exec.Error
if errors.As(res.Err, &execErr) || strings.Contains(res.Err.Error(), "not found in PATH") {
// fall back to manual update instructions instead of retrying
}
return res.Err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- pnpm not found in PATH: %w
- %s not found in PATH: %w
- lark-cli not found
- npm install timed out after %s
- cannot locate binary: %w
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/31f0352fcec07492.
Report an issue: GitHub.