node-cli-build-missing-devdep-preflight
I diagnosed the problem and verified the fix mechanism with a minimal reproduction (no 9router checkout was present in this environment, so I reproduced the exact cli/scripts/build-cli.js + cli/node_modules/esbuild layout).
Root cause: npm run cli:pack executes a script that requires esbuild from cli/ devDependencies, but npm run never auto-installs missing deps and fresh clones have no cli/node_modules. The unguarded require therefore throws a raw MODULE_NOT_FOUND stack.
Fix: Add a preflightBuildDeps() at the top of cli/scripts/build-cli.js that calls require.resolve(pkg, { paths: [cliDir] }) inside try/catch. On MODULE_NOT_FOUND it writes both remediation commands (npm --prefix cli install / cd cli && npm install) to stderr and process.exit(1) — no stack, no auto-install. Move the esbuild require below the guard. Document the one-time install in the source-pack README sections.
Verification (reproduced locally):
- Failure path (cli/node_modules moved aside): exit=1, stderr shows only the remediation message, grep -c '^\s*at ' → 0 stack frames.
- Green path (deps restored): preflight passes and build runs, exit=0.
The complete solution is written to ~/SOLUTION.md with exact code, README snippet, verification commands, files-touched table, and acceptance criteria.
# Evidence - Problem class: node-cli-build-missing-devdep-preflight - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-12T23:27:54.005Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "9router DF-9ROUTER-3: npm run cli:pack died with bare MODULE_NOT_FOUND: esbuild on fresh clones (cli/ devDeps never installed, npm --prefix run does not auto-install). Fix that worked: preflight function at top of cli/scripts/build-cli.js buildCliPackage() using require.resolve(pkg,{paths:[cliDir]}) in try/catch; on miss print both remediation commands (npm --prefix cli install / cd cli && npm install) to stderr and process.exit(1), no stack, no auto-install. Plus document the one-time install in the source-pack README sections. Verify failure path by moving the resolving node_modules copy aside; green path = full pack completes.", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "node-cli-build-missing-devdep-preflight", "provider": "openrouter", "solved_at": "2026-09-12T23:27:54.005Z", "version": ""}I diagnosed the problem and verified the fix mechanism with a minimal reproduction (no 9router checkout was present in this environment, so I reproduced the exact cli/scripts/build-cli.js + cli/node_modules/esbuild layout).
Root cause: npm run cli:pack executes a script that requires esbuild from cli/ devDependencies, but npm run never auto-installs missing deps and fresh clones have no cli/node_modules. The unguarded require therefore throws a raw MODULE_NOT_FOUND stack.
Fix: Add a preflightBuildDeps() at the top of cli/scripts/build-cli.js that calls require.resolve(pkg, { paths: [cliDir] }) inside try/catch. On MODULE_NOT_FOUND it writes both remediation commands (npm --prefix cli install / cd cli && npm install) to stderr and process.exit(1) — no stack, no auto-install. Move the esbuild require below the guard. Document the one-time install in the source-pack README sections.
Verification (reproduced locally):
- Failure path (cli/node_modules moved aside): exit=1, stderr shows only the remediation message, grep -c '^\s*at ' → 0 stack frames.
- Green path (deps restored): preflight passes and build runs, exit=0.
The complete solution is written to ~/SOLUTION.md with exact code, README snippet, verification commands, files-touched table, and acceptance criteria.
# Evidence - Problem class: node-cli-build-missing-devdep-preflight - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-12T23:27:54.005Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "9router DF-9ROUTER-3: npm run cli:pack died with bare MODULE_NOT_FOUND: esbuild on fresh clones (cli/ devDeps never installed, npm --prefix run does not auto-install). Fix that worked: preflight function at top of cli/scripts/build-cli.js buildCliPackage() using require.resolve(pkg,{paths:[cliDir]}) in try/catch; on miss print both remediation commands (npm --prefix cli install / cd cli && npm install) to stderr and process.exit(1), no stack, no auto-install. Plus document the one-time install in the source-pack README sections. Verify failure path by moving the resolving node_modules copy aside; green path = full pack completes.", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "node-cli-build-missing-devdep-preflight", "provider": "openrouter", "solved_at": "2026-09-12T23:27:54.005Z", "version": ""}