JuliusBrussee/caveman · error · Error
target already exists
Error message
target already exists: ${path} What it means
Before scaffolding, assertAbsent stats the target path; if the path already exists (file or directory), it throws to prevent clobbering an existing project. Only ENOENT is treated as 'safe to proceed'.
Solutions
- Choose a different project name or run in another directory
- Delete or rename the existing target if it is safe to remove: `rm -rf my-app`
- Inspect the existing target first — if it is a leftover from a failed run, remove it and re-run
Example fix
// before npm create @caveman-ai/agent@latest my-app # ./my-app already exists // after rm -rf ./my-app # only if disposable npm create @caveman-ai/agent@latest my-app
Defensive patterns
Strategy: validation
Validate before calling
import { stat } from "node:fs/promises";
try {
await stat(target);
throw new Error(`refusing to overwrite existing target: ${target}`);
} catch (e) {
if ((e as NodeJS.ErrnoException).code !== "ENOENT") throw e;
} Type guard
async function isFreePath(path: string): Promise<boolean> {
try { await stat(path); return false; } catch (e) { return (e as NodeJS.ErrnoException).code === "ENOENT"; }
} Try / catch
try {
await main();
} catch (error) {
if (error instanceof Error && error.message.startsWith("target already exists")) {
console.error(`${error.message} — remove it or pick another name`);
process.exitCode = 1;
} else throw error;
} Prevention
- Check the target directory with ls before scaffolding
- Clean up leftover directories from failed runs before retrying
- Use unique project names or fresh working directories in CI
When it happens
Trigger: Running the scaffolder with a target name whose directory or file already exists in the current working directory, e.g. re-running the create command after a previous successful or partial run.
Common situations: Re-running the command after a failed install left the directory behind; choosing `my-app` when `my-app` already exists; colliding with an unrelated existing file/folder of the same name.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- already exists; refusing to overwrite an unjournaled plugin
- awscreds: read container authorization token file
- cannot persist MCP ownership journal at
- cannot safely launch Windows command shim
- cave_sandbox_source_read_root_refused
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/6e98a0dd2d0453ee.
Report an issue: GitHub.
Appendix: source
Thrown at packages/create-caveman-agent/src/index.ts:314
return "GEMINI_API_KEY (or GOOGLE_API_KEY)";
}
function parseProvider(value: string): Provider {
const normalized = value.trim().toLowerCase();
if (normalized === "anthropic" || normalized === "openai" || normalized === "google") return normalized;
throw new Error(`unsupported provider ${JSON.stringify(value)}`);
}
function safeName(value: string): string {
const normalized = value.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
if (!normalized) throw new Error("project name must contain a letter or number");
return normalized.slice(0, 96);
}
async function assertAbsent(path: string): Promise<void> {
try {
await stat(path);
throw new Error(`target already exists: ${path}`);
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
}
}
main().catch((error) => {
const message = error instanceof Error ? error.message : String(error);
process.stderr.write(`create-caveman-agent: ${message}\n`);
process.exitCode = 1;
});
View on GitHub (pinned to 3ee70a1026)