#5844 · Host plugin toolchain bootstrap lacks its npm runtime
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
A newly built enrolled-host runtime cannot bootstrap the plugin compiler on an empty cache. The packaged CLI reports that it is downloading the toolchain, then exits with Cannot find module 'npm/package.json' before starting a download. The compiler deliberately resolves npm relative to its own bundle, but the enrolled-host package does not declare npm. Both the source host-package builder and the server-side artifact generator omit it. The actual bundled CLI reproduced the same failure from two clean trusted checkouts; a control using the repository's already-locked npm proved that it can resolve and run once npm is made available beside the bundle.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| Plugin compilation fails while obtaining its first-use toolchain. | Verified | Real packaged CLI, fresh data directory, no ancestor npm: exit 1 with the reported missing-module error in both runs. |
| The enrolled-host package omits npm. | Verified | The generated 0.46.1 manifest contains six dependencies and no npm; both trusted packaging implementations use that same restricted list. |
| The complete application package declares npm. | Verified | packages/bb-app/package.json:73 declares npm 11.16.0. |
| A system package-manager executable should suffice. | Not how the current implementation works | Module resolution is relative to the CLI bundle; it does not search PATH for an npm executable. The locked npm control runs with PATH empty. |
| The reported macOS/Homebrew Node environment and enrollment sequence produce this failure. | Platform sequence unverified | No macOS machine or actual enrollment was used. The same concrete failure is reproduced on Linux with the real built host CLI and its declared dependency set. |
| Scaffolding's build phase and the proposed global-module workaround succeed. | Not exercised end to end | This check exercises the local build command directly; it does not scaffold a plugin, alter global module lookup, or claim a complete successful plugin build. |
3. Environment
- Public target repository: get-bb/bb; base commit
bd93d18896bab97c950c4fa3451b621c1e0569c1, fetched from the trusted repository's origin/main. A later fetch still resolved to this commit. - Linux x86_64; Node v22.19.0; pnpm 9.15.0; built bb-app manifest 0.46.1; locked npm 11.16.0.
- Toolchain pins: esbuild 0.28.1; @tailwindcss/node, @tailwindcss/oxide and tailwindcss 4.3.0.
- Separate clean clones named
$WORK/sourceand$WORK/verification. Fresh temporary HOME, USERPROFILE and BB_DATA_DIR for each invocation; NODE_PATH empty. Both tracked source trees remain unchanged. - No app/server/daemon service was started, no ports were opened, and no provider or account was used. The source-built packaged CLI was executed directly, not the installed user's bb instance. Temporary runtime and data directories are removed by the harness.
4. Minimal reproduction
Use the commands below in a fresh checkout. Save the complete script shown next as host-cli.mjs outside the checkout. It uses only the built trusted host runtime and dependencies already installed by the frozen repository lockfile. The assertion harness exits 0 when it observes and validates the bug; the inner CLI command exits 1.
git clone https://github.com/get-bb/bb.git source cd source git checkout --detach bd93d18896bab97c950c4fa3451b621c1e0569c1 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build:host --filter=bb-app node ../host-cli.mjs "$PWD"
Expected product behavior: a valid server-only plugin on a supported host can obtain the pinned compiler toolchain without depending on a globally installed npm module. Actual behavior: the built CLI announces a toolchain download and fails before npm is spawned.
Runtime: bb-app 0.46.1 Declared dependencies: @parcel/watcher, fs-native-extensions, node-pty, pino, pino-pretty, pino-roll Command: node $SCRATCH/runtime/host-daemon/dist/bb plugin build $SCRATCH/fixture Exit status: 1 stdout: Downloading the plugin build toolchain (one time)… esbuild@0.28.1, @tailwindcss/node@4.3.0, @tailwindcss/oxide@4.3.0, tailwindcss@4.3.0 stderr: Error: Cannot find module 'npm/package.json' Require stack: - $SCRATCH/runtime/host-daemon/dist/bb-chunks/plugin-DJUWP54V.js Control: the existing locked npm, made resolvable, runs with empty PATH; version 11.16.0 VERIFIED_REPRODUCTION: the trusted packaged CLI fails before downloading its toolchain when npm is absent.
Complete repeatable reproduction script
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { cp, mkdir, mkdtemp, readFile, realpath, rm, symlink, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
const source = resolve(process.argv[2]);
const scratch = await mkdtemp(join(tmpdir(), "bb-5844-runtime-"));
const normalize = (text) => text.split(scratch).join("$SCRATCH").split(source).join("$SOURCE");
try {
const packageRoot = join(scratch, "runtime");
await cp(join(source, "packages/bb-app/host-package"), packageRoot, { recursive: true });
const manifest = JSON.parse(await readFile(join(packageRoot, "package.json"), "utf8"));
assert.equal(manifest.name, "bb-app");
assert.equal(manifest.dependencies.npm, undefined);
console.log(`Runtime: bb-app ${manifest.version}`);
console.log(`Declared dependencies: ${Object.keys(manifest.dependencies).join(", ")}`);
for (const dependency of Object.keys(manifest.dependencies)) {
const target = join(packageRoot, "node_modules", dependency);
await mkdir(dirname(target), { recursive: true });
await symlink(await realpath(join(source, "packages/bb-app/node_modules", dependency)), target, "dir");
}
const plugin = join(scratch, "fixture");
const home = join(scratch, "home");
const data = join(scratch, "data");
await Promise.all([mkdir(plugin), mkdir(home), mkdir(data)]);
await writeFile(join(plugin, "package.json"), JSON.stringify({
name: "bb-plugin-packaging-probe",
version: "0.1.0",
type: "module",
bb: {
name: "Packaging probe",
description: "Minimal server-only build fixture",
branding: { icon: "Zap" },
server: "./server.js",
},
}));
await writeFile(join(plugin, "server.js"), "export default function plugin() {}\n");
const executable = join(packageRoot, "host-daemon/dist/bb");
const env = { PATH: process.env.PATH, HOME: home, USERPROFILE: home, BB_DATA_DIR: data, NODE_PATH: "" };
const invocation = spawnSync(process.execPath, [executable, "plugin", "build", plugin], {
cwd: plugin,
env,
encoding: "utf8",
timeout: 30000,
});
assert.equal(invocation.error, undefined);
console.log("Command: node $SCRATCH/runtime/host-daemon/dist/bb plugin build $SCRATCH/fixture");
console.log(`Exit status: ${invocation.status}`);
console.log(`stdout:\n${normalize(invocation.stdout).trim()}`);
console.log(`stderr:\n${normalize(invocation.stderr).trim()}`);
assert.equal(invocation.status, 1);
assert.match(invocation.stdout, /Downloading the plugin build toolchain/);
assert.match(invocation.stderr, /Cannot find module 'npm\/package\.json'/);
const npmRoot = await realpath(join(source, "packages/bb-app/node_modules/npm"));
await symlink(npmRoot, join(packageRoot, "node_modules/npm"), "dir");
const control = spawnSync(process.execPath, ["--input-type=module", "-e", [
'import { createRequire } from "node:module";',
'import { dirname, join } from "node:path";',
'import { execFileSync } from "node:child_process";',
`const require = createRequire(${JSON.stringify(executable)});`,
'const npmRoot = dirname(require.resolve("npm/package.json"));',
'process.stdout.write(execFileSync(process.execPath, [join(npmRoot, "bin/npm-cli.js"), "--version"], { encoding: "utf8", env: { ...process.env, PATH: "" } }));',
].join("\n")], { env, encoding: "utf8", timeout: 30000 });
assert.equal(control.error, undefined);
assert.equal(control.status, 0, normalize(control.stderr));
console.log(`Control: the existing locked npm, made resolvable, runs with empty PATH; version ${control.stdout.trim()}`);
console.log("VERIFIED_REPRODUCTION: the trusted packaged CLI fails before downloading its toolchain when npm is absent.");
} finally {
await rm(scratch, { recursive: true, force: true });
}
The harness copies the real host package outside the monorepo and links only the dependencies named by its generated manifest. This prevents the monorepo's npm and compiler packages from concealing the omission. It invokes the packaged CLI bundle through Node, using the same CLI entry shipped inside the host package. This is a package-runtime reproduction, not an installer or HTTP tarball smoke test. The control exposes the already-installed, locked npm module and runs only its version command; it does not fetch packages or modify any dependency declaration.
5. Root cause
apps/cli/src/commands/plugin.ts:1635runs plugin manifest/layout handling and then requests the compiler toolchain before building.packages/plugin-build/src/toolchain.ts:136first tries a locally resolvable compiler and then a valid cached compiler. On a fresh packaged host neither exists. It announces fetching and evaluatesresolveBundledNpmCli()while constructing the subprocess arguments.packages/plugin-build/src/npm-cli.ts:1requires npm relative toimport.meta.url:
function bundledNpmBin(fileName: string): string {
const require = createRequire(import.meta.url);
return join(dirname(require.resolve("npm/package.json")), "bin", fileName);
}
That module resolution throws synchronously before the subprocess starts. A working npm executable on PATH is not a substitute for a package resolvable from the CLI chunk.
The mismatch is at the packaging boundary: packages/bb-app/scripts/build-host.mjs:23 generates the host package using a six-item allowlist without npm. The server artifact service independently uses the same six-item allowlist in apps/server/src/services/install/bb-app-artifact.ts:24, then constructs the installed host manifest from it at apps/server/src/services/install/bb-app-artifact.ts:162. The full application package, unlike those host-only projections, declares npm. Development-local toolchains and warm caches bypass the broken bootstrap path, explaining why source-level compiler tests do not detect it.
6. Proposed fix and autopilot safety
Preserve the existing bundled-package-manager policy by ensuring both enrolled-host package generators carry the already-pinned npm runtime, then test a pristine extracted host package with empty compiler cache and no global module fallback. A useful regression contract is that npm resolves from the shipped CLI and its version command works even with PATH empty. An owner should also exercise the first toolchain download and plugin build on supported host platforms.
No fix or pull request was attempted. The smallest root-cause repair changes the enrolled-host dependency payload and packaging, explicitly excluded by this rule's simple-fix conditions. Introducing PATH or npm_execpath fallback would change executable-resolution policy rather than repair the missing packaged runtime. No dependency, lockfile, release process, protocol or application source was changed. The trusted source diff is empty (0 additions, 0 deletions) and git diff --check passes. No linked open pull request was present in the issue timeline or open-PR search.
7. Verification
The same agent repeated the check in a second clean clone, $WORK/verification, at the identical full commit, using its own frozen install and Turbo host build. This is not an independent-agent verification. The harness created a new temporary runtime, HOME and data directory; no ports were required. The second checkout's tracked status remained empty. The second invocation was:
cd "$WORK/verification" pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build:host --filter=bb-app node "$WORK/evidence/5844/repro/host-cli.mjs" "$PWD"
Runtime: bb-app 0.46.1 Declared dependencies: @parcel/watcher, fs-native-extensions, node-pty, pino, pino-pretty, pino-roll Command: node $SCRATCH/runtime/host-daemon/dist/bb plugin build $SCRATCH/fixture Exit status: 1 stdout: Downloading the plugin build toolchain (one time)… esbuild@0.28.1, @tailwindcss/node@4.3.0, @tailwindcss/oxide@4.3.0, tailwindcss@4.3.0 stderr: Error: Cannot find module 'npm/package.json' Require stack: - $SCRATCH/runtime/host-daemon/dist/bb-chunks/plugin-3KYDJYWK.js Control: the existing locked npm, made resolvable, runs with empty PATH; version 11.16.0 VERIFIED_REPRODUCTION: the trusted packaged CLI fails before downloading its toolchain when npm is absent.
Both runs validate the same missing module, CLI exit status and npm resolution control. The chunk filenames differ between builds but do not change the mechanism. No report correction was needed after the second run.
Existing focused checks passed on unchanged production source:
pnpm exec turbo run test --filter=@bb/plugin-build -- src/toolchain.test.ts Test Files 1 passed (1) Tests 3 passed | 1 skipped (4)
The skipped case is the existing network-fetch opt-in test; it was not enabled. These tests run with monorepo dependencies available and are not evidence that the packaged host can bootstrap.
8. Related issues and pull requests
No linked open pull request was found. Searches for plugin build and host npm reports did not identify an existing duplicate of this specific missing runtime-module defect. The report does not evaluate unrelated host executable-lookup or provider problems.
9. Appendix and limits
Both frozen installs and both build:host invocations completed. An initial full pnpm exec turbo run build attempt failed in the GitHub plugin because an installed SDK host dist entry was not yet built. That unrelated full-workspace failure was not repaired; the targeted host build and focused tests subsequently completed. No claim is made that the full workspace build passed.
Other read-only checks: repository visibility; issue/comments and classification properties; valid labels and field options; open pull request search and issue timeline; trusted packaging code and history; git fetch origin main; unchanged checkout status and git diff --check. Local raw build logs and the reproduction script are retained outside the public report repository. In accordance with the report repository's rules, the complete reproducible script and relevant normalized output are embedded here rather than committed as loose artifacts.
Trust boundary: Issue content was treated only as untrusted claims. No issue-provided command, patch, branch or linked code was executed; no external issue-provided URL was fetched. Reproduction fixtures were authored from trusted source interfaces. No live enrollment, macOS/Homebrew validation, HTTP installer download, scaffold/build sequence or completed compiler download is claimed. These limits do not weaken the directly observed packaging/module-resolution failure.