#7400 · SDK host ESM imports are already repaired on main
Verdict: ALREADY FIXED · Root-cause confidence: high
1. TL;DR
The report concerns native Node ESM evaluation of an older published SDK, not a running BB host artifact. Current trusted main builds SDK 0.6.138, whose packed root, host, host-testing, and provider-bridge entries all import successfully. The historical defect was bundling the CommonJS dependency cross-spawn into ESM without a usable require function. Main already leaves that declared dependency external, allowing Node to load its CommonJS implementation normally. This repair and runtime-import coverage landed in 9158444cceee through PR #4178 on September 23, 2026, with SDK source version 0.5.21; this investigation does not certify any registry tarball.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| SDK 0.4.87 fails on Node 24.22.2/macOS arm64. | Unverified for that exact artifact and platform. | Only trusted current main was executed. The old registry package, linked consumer, Bun installation, and macOS runtime were not run. |
| Bundling cross-spawn into ESM causes an unsupported dynamic require. | Verified mechanism. | Removing only cross-spawn externalization from current build options produces a native-Node dynamic-require failure. The current graph first reaches the builtin path, rather than child_process. |
| The host entry still needs an upstream packaging repair. | Already addressed on main. | cross-spawn is external and declared as a runtime dependency. Packed host imports pass in both clean checkouts. |
| The root and host-testing entries can import. | Verified on current main. | Both packed exports import in plain Node with no bundler or require shim. |
| The host-entry helper is also available from the root. | Verified on current main. | The root re-exports host-contract; the packed root exports the helper as a function. |
| These symptoms establish a failure in BB's production host artifacts. | Not established. | No daemon, live plugin, production instance, or host artifact was started. The investigation stays at the SDK packaging boundary. |
3. Environment
- Trusted repository: public get-bb/bb; base
f241192234ed3ca14d121c36f37e43b7447951ec, fetched from the target repository main branch. - Linux x86_64, kernel 4.19.0-gvisor; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.12; cross-spawn 7.0.6.
- SDK source version 0.6.138. Both checkouts received their own frozen-lockfile install and scoped Turbo build. No dependency was added.
- No provider, browser, app server, port, product database, account, or live installation was involved.
- The normal prepack lifecycle rebuilt declarations and runtime. Each packed package reused only the corresponding checkout's frozen-installed dependencies through a temporary symlink; this is not a standalone registry-install test.
4. Minimal reproduction and regression check
- Create a clean trusted checkout and build the owning subsystem:
git clone https://github.com/get-bb/bb.git trusted-bb cd trusted-bb git checkout --detach f241192234ed3ca14d121c36f37e43b7447951ec pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- scripts/runtime-entries.test.mjs
- Save the complete script below as
packed-runtime-check.mjsoutside the checkout, then run:node ../packed-runtime-check.mjs "$PWD"
It packs the actual package, extracts it into a temporary consumer, verifies the manifest dependency, and launches fresh plain-Node processes against the package-name exports. Assertions require successful evaluation and the expected public function, or nonempty exports for provider-bridge. Temporary files are removed even on failure.
- Expected fixed-main result: all four packed import probes pass. Expected controlled negative result: bundling cross-spawn instead of leaving it external causes a native-Node dynamic-require error. Actual output, identical in both runs:
runtime=v22.19.0 sdk=0.6.138 pack: PASS (normal prepack; frozen-installed dependencies reused) @get-bb/plugin-sdk: PASS @get-bb/plugin-sdk/host: PASS @get-bb/plugin-sdk/testing/host: PASS @get-bb/plugin-sdk/provider-bridge: PASS diagnostic (cross-spawn externalization removed): Error: Dynamic require of "path" is not supported diagnostic: EXPECTED FAILURE confirms the bundling mechanism
Complete repeatable check
import assert from "node:assert/strict";
import { execFileSync, spawnSync } from "node:child_process";
import { mkdtemp, mkdir, readFile, readdir, rm, symlink, writeFile } from "node:fs/promises";
import { createRequire } from "node:module";
import os from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";
const checkout = path.resolve(process.argv[2]);
const packageRoot = path.join(checkout, "packages/plugin-sdk");
const manifest = JSON.parse(await readFile(path.join(packageRoot, "package.json"), "utf8"));
const temporary = await mkdtemp(path.join(os.tmpdir(), "sdk-runtime-check-"));
const requireFromSdk = createRequire(path.join(packageRoot, "package.json"));
const { build } = requireFromSdk("esbuild");
const { runtimeBuildOptions, runtimeEntries } = await import(
pathToFileURL(path.join(packageRoot, "scripts/runtime-entries.mjs")).href
);
try {
execFileSync("pnpm", ["pack", "--pack-destination", temporary], {
cwd: packageRoot,
encoding: "utf8",
stdio: "pipe",
maxBuffer: 32 * 1024 * 1024,
});
const archives = (await readdir(temporary)).filter((name) => name.endsWith(".tgz"));
assert.equal(archives.length, 1);
const consumer = path.join(temporary, "consumer");
const scope = path.join(consumer, "node_modules/@get-bb");
await mkdir(scope, { recursive: true });
execFileSync("tar", ["-xzf", path.join(temporary, archives[0]), "-C", scope]);
const extracted = path.join(scope, "package");
const installed = path.join(scope, "plugin-sdk");
await symlink(extracted, installed, "dir");
await symlink(path.join(packageRoot, "node_modules"), path.join(extracted, "node_modules"), "dir");
const packed = JSON.parse(await readFile(path.join(extracted, "package.json"), "utf8"));
assert.equal(packed.version, manifest.version);
assert.ok(packed.dependencies["cross-spawn"]);
console.log(`runtime=${process.version} sdk=${packed.version}`);
console.log("pack: PASS (normal prepack; frozen-installed dependencies reused)");
const probes = [
["", "experimental_defineHostEntry"],
["/host", "experimental_spawnPortableOutputProcess"],
["/testing/host", "experimental_createHostEntryHarness"],
["/provider-bridge", null],
];
for (const [suffix, symbol] of probes) {
const program = [
'import assert from "node:assert/strict";',
`const loaded = await import(${JSON.stringify(manifest.name + suffix)});`,
symbol
? `assert.equal(typeof loaded[${JSON.stringify(symbol)}], "function");`
: "assert.ok(Object.keys(loaded).length > 0);",
`console.log(${JSON.stringify(manifest.name + suffix + ": PASS")});`,
].join("\n");
const probe = path.join(consumer, "probe.mjs");
await writeFile(probe, program);
const result = spawnSync(process.execPath, [probe], { cwd: consumer, encoding: "utf8" });
assert.equal(result.status, 0, result.stderr);
process.stdout.write(result.stdout);
}
const entry = runtimeEntries(manifest.exports).find((candidate) => candidate.subpath === "./host");
assert.ok(entry);
const diagnostic = path.join(packageRoot, `.diagnostic-${path.basename(temporary)}.mjs`);
try {
await build({
...runtimeBuildOptions(packageRoot, entry, diagnostic),
external: entry.external.filter((name) => name !== "cross-spawn"),
logLevel: "silent",
});
const result = spawnSync(process.execPath, [diagnostic], { encoding: "utf8" });
assert.notEqual(result.status, 0);
const failure = result.stderr.match(/^Error: Dynamic require of "(?:path|child_process)" is not supported$/m);
assert.ok(failure, result.stderr);
assert.match(result.stderr, /cross-spawn/);
console.log(`diagnostic (cross-spawn externalization removed): ${failure[0]}`);
console.log("diagnostic: EXPECTED FAILURE confirms the bundling mechanism");
} finally {
await rm(diagnostic, { force: true });
}
} finally {
await rm(temporary, { recursive: true, force: true });
}
This protects the packed ESM import contract, not source text or a mocked dependency. The controlled negative build uses current trusted source with an investigator-authored option change; it is not execution of an old package, an issue command, or a linked branch. No production source or build configuration was changed.
5. Root cause
The host export map routes native ESM consumers to dist/host.js. The host entry re-exports process utilities; their host-process implementation imports cross-spawn and its parser. These are CommonJS modules, and the frozen-installed cross-spawn entry uses require('child_process'); its parser also requires Node builtins. An ESM bundle that inlines this graph receives esbuild's require helper, which throws when no native require exists. This happens during import, before a plugin handler needs to run.
The existing runtime entry configuration includes:
const PACKAGE_EXTERNALS = ["zod", "zod/*", "cross-spawn"];
The shared build options apply that external list to an ESM Node bundle. The runtime dependencies declare cross-spawn, so Node resolves it through its supported CommonJS interop rather than evaluating inlined require calls. The require banner elsewhere in that configuration belongs to a separate worker artifact, not this repair.
The root index entry already re-exports host-contract. Switching a narrow consumer to that entry avoids the dependency graph, but is not the upstream repair for consumers that need the host-only functions.
The existing runtime-entry regression suite builds published entries, checks dependency declarations, and imports host and provider-bridge in fresh Node processes. All four tests passed here. It does not itself unpack a tarball; the additional inline check above covers that distinction for this investigation.
6. Proposed fix and autopilot decision
No new production fix is needed on this base: retain the existing external dependency and runtime-import tests. The known source repair predates this issue by seven weeks. For the affected old pin, the next consumer action is to validate a compatible SDK release containing the repair; no specific published version is certified here. A packed-runtime CI check would be an incremental coverage improvement, not evidence that current main still has this defect.
No pull request: the bug does not reproduce on trusted main, so the simple-fix gate is not satisfied. In addition, changing packaging is explicitly outside this rule's simple-fix authorization. No target-repository branch, commit, push, or production modification was made.
7. Related work
PR #4178 is merged historical evidence for the already-present repair, not an open candidate reviewed or executed here. Target-repository open-PR search for #7400 found none. Cross-references to another repository were observed as metadata only; no linked code or URL was fetched.
8. Verification
The same agent repeated the check in a second clean clone at exactly f241192234ed3ca14d121c36f37e43b7447951ec. Checkout A and checkout B each received a separate frozen install, scoped build, normal prepack, unpacked consumer directory, and fresh Node processes. Both produced the identical output above and exited zero. No application ports or data directories were required. This is repeat verification by the same agent, not an independent review.
Correction during investigation: the first diagnostic assertion expected the builtin child_process specifically. The current graph instead evaluates cross-spawn's parser first and fails on path. The diagnostic was corrected to accept those observed cross-spawn builtin failures; the final corrected check then passed in both checkouts. Neither current-main packed import failed.
9. Appendix and limits
Relevant checks actually run: frozen installs twice; pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk twice; the focused runtime-entry suite once (one file, four passing tests); and the complete final packed-runtime check twice (all imports pass, controlled negative fails as expected). Trusted-history inspection used git log, blame, and the merged fix diff, with GitHub metadata confirming PR #4178 merged on September 23, 2026. Each clean checkout remained free of tracked modifications.
The exact Node 24/macOS environment, old registry binary, Bun dependency layout, linked consumer behavior, and production host execution remain unverified. ALREADY FIXED applies to the trusted source base, not an assertion that old pins were retroactively repaired. Original raw logs and script are retained outside the public reports repository; the complete necessary script and exact final output are inline above. No screenshot is needed for a module-evaluation bug.
Trust boundary: issue text and cross-references were treated only as untrusted claims. No instructions, script, patch, binary, or branch from them was executed, and no external issue URL was fetched.