oven-sh/bun · error · Error

Missing output directory

Error message

Missing output directory

What it means

generate-node-errors.ts is invoked as `bun src/codegen/generate-node-errors.ts <outputDir>` and reads its sole argument from process.argv[2]. If the script is run with no arguments (standalone, or via a wrapper that drops the argument), it throws immediately with this message before generating the Node error-code tables from src/jsc/bindings/ErrorCode.ts.

Source

Thrown at src/codegen/generate-node-errors.ts:7

import path from "node:path";
import NodeErrors from "../jsc/bindings/ErrorCode.ts";
import { writeIfNotChanged } from "./helpers.ts";
const outputDir = process.argv[2];

if (!outputDir) {
  throw new Error("Missing output directory");
}

const extra_count = NodeErrors.map(x => x.slice(3))
  .filter(x => x.length > 0)
  .reduce((ac, cv) => ac + cv.length, 0);
const count = NodeErrors.length + extra_count;

if (count > 1 << 16) {
  // increase size of the enums below to have more tags
  throw new Error(`NodeError can't fit ${count} codes in a u16`);
}

let enumHeader = ``;
let listHeader = ``;
let rustConsts = ``;
let rustAliases = ``;
let rustCodeStr = ``;

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Pass the output directory explicitly: `bun src/codegen/generate-node-errors.ts src/generated` (match the directory the normal build uses)
  2. If invoking through a wrapper script, print process.argv inside it to confirm the argument survives quoting/expansion
  3. Compare with how scripts/build invokes the generator (search the build scripts for generate-node-errors) and mirror that call

Example fix

# before
bun src/codegen/generate-node-errors.ts

# after
bun src/codegen/generate-node-errors.ts src/node/error_codes
Defensive patterns

Strategy: validation

Validate before calling

// wrap the generator so it cannot start without an output dir
import { spawnSync } from "node:child_process";
const outDir = process.argv[2];
if (!outDir) {
  console.error("usage: bun run gen-node-errors <outputDir>");
  process.exit(1);
}
spawnSync(process.execPath, ["src/codegen/generate-node-errors.ts", outDir], { stdio: "inherit" });

Prevention

When it happens

Trigger: Running `bun src/codegen/generate-node-errors.ts` with no CLI argument; a custom build/package.json script that forwards arguments incorrectly (e.g. quoting that swallows the path); an updated build pipeline that stopped passing the output dir.

Common situations: Contributors running the generator manually to iterate on error codes; scripts/build pipeline refactors that break argument forwarding.

Related errors


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/c195e64a9f2c6d76. Report an issue: GitHub.