remix-run/react-router · warning · Error
Exiting to avoid overwriting files
Error message
Exiting to avoid overwriting files
What it means
In an interactive shell, when file collisions are detected the CLI asks 'Do you wish to continue?' (initial answer false). Answering 'no' throws this error to abort scaffolding cleanly, leaving existing files untouched. It is a deliberate user cancellation, not a malfunction.
Solutions
- Re-run and answer yes at the prompt, or add --overwrite to skip the question
- Scaffold into a fresh empty directory instead
- Delete or move the colliding files listed in the prompt, then re-run
Example fix
# before: prompted, answered no -> abort npx create-react-router ./existing-dir # after: decide up front npx create-react-router ./existing-dir --overwrite
Defensive patterns
Strategy: fallback
Try / catch
try {
await createReactRouter(args);
} catch (e) {
if ((e as Error).message === "Exiting to avoid overwriting files") {
// Deliberate user cancellation — exit cleanly, existing files are untouched
process.exit(0);
}
throw e;
} Prevention
- Use --overwrite up front when overwriting is intended — the prompt defaults to 'no'
- Scaffold into an empty directory to avoid the prompt entirely
- In automation, never leave the overwrite decision to an interactive prompt
When it happens
Trigger: Declining the overwrite confirmation prompt after the CLI listed files in the target directory that the template would overwrite.
Common situations: Intentional cancel after seeing the collision list; users realizing mid-scaffold they picked the wrong directory.
Related errors
- File collisions detected in a non-interactive environment
- No project directory provided
- " " is an invalid template. Run to see supported template…
- No available port found
- ️⚠️ Oops, Node v detected. react-router requires a Node…
AI-assisted analysis of remix-run/react-router@6beaca3952 (2026-08-18).
Data as JSON: /api/errors/bbb15fec95b51d08.
Report an issue: GitHub.
Appendix: source
Thrown at packages/create-react-router/index.ts:415
if (ctx.debug) {
debug(`Colliding files:${getFileList(" ")}`);
}
let { overwrite } = await ctx.prompt({
name: "overwrite",
type: "confirm",
label: title("overwrite"),
message:
`Your project directory contains files that will be overwritten by\n` +
` this template (you can force with \`--overwrite\`)\n\n` +
` Files that would be overwritten:` +
`${getFileList(" ")}\n\n` +
` Do you wish to continue?\n` +
` `,
initial: false,
});
if (!overwrite) {
throw new Error("Exiting to avoid overwriting files");
}
}
}
await cp(ctx.tempDir, ctx.cwd, {
filter(src) {
// We never copy .git/ or node_modules/ directories since it's highly
// unlikely we want them copied - and because templates are primarily
// being pulled from git tarballs which won't have .git/ and shouldn't
// have node_modules/
let file = stripDirectoryFromPath(ctx.tempDir, src);
let isIgnored = IGNORED_TEMPLATE_DIRECTORIES.includes(file);
if (isIgnored) {
if (ctx.debug) {
debug(`Skipping copy of ${file} directory from template`);
}
return false;
}View on GitHub (pinned to 6beaca3952)