Skip to content

getGlobalNpmRoot() does not work with bun as npmCommand #3809

@thirtythreeforty

Description

@thirtythreeforty

What happened?

When "npmCommand": ["bun"] is configured in settings.json, pi fails to start because it invokes bun root -g, which doesn't exist:

error: Failed to run bun root -g: error: Script not found "root"

I'd like to send a PR fixing this by adding a simple check for the Bun runtime, using the Bun-checking logic already in config.ts:

diff --git a/packages/coding-agent/src/core/package-manager.ts b/packages/coding-agent/src/core/package-manager.ts
index a8e996ae..296681c4 100644
--- a/packages/coding-agent/src/core/package-manager.ts
+++ b/packages/coding-agent/src/core/package-manager.ts
@@ -18,3 +18,3 @@ import ignore from "ignore";
 import { minimatch } from "minimatch";
-import { CONFIG_DIR_NAME } from "../config.js";
+import { CONFIG_DIR_NAME, isBunRuntime } from "../config.js";
 import { type GitSource, parseGitUrl } from "../utils/git.js";
@@ -1834,4 +1834,8 @@ export class DefaultPackageManager implements PackageManager {
         }
-        const result = this.runNpmCommandSync(["root", "-g"]);
-        this.globalNpmRoot = result.trim();
+        if (isBunRuntime) {
+            const binDir = this.runCommandSync("bun", ["pm", "bin", "-g"]).trim();
+            this.globalNpmRoot = join(dirname(binDir), "install", "global", "node_modules");
+        } else {
+            this.globalNpmRoot = this.runNpmCommandSync(["root", "-g"]).trim();
+        }
         this.globalNpmRootCommandKey = commandKey;

(Bun doesn't provide a direct analogue for root -g.) Applied locally, this fixes the problem and lets pi start and use extensions. (pi add ... already works fine with bun, as it simply calls bun install -g ..., which works fine.)

This was previously reported unnoticed in #2544.

Steps to reproduce

  1. Add "npmCommand": ["bun"] to pi's settings.json.
  2. Install Bun and use it to install pi: bunx @mariozechner/pi-coding-agent.

Expected behavior

I expect pi to start when using bun as the package manager - especially as it already has explicit support for Bun as runtime in several other places.

Version

0.70.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions