{"record":{"id":"bbb15fec95b51d08","repo":"remix-run/react-router","slug":"exiting-to-avoid-overwriting-files","errorCode":null,"errorMessage":"Exiting to avoid overwriting files","messagePattern":"Exiting to avoid overwriting files","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/create-react-router/index.ts","lineNumber":415,"sourceCode":"      if (ctx.debug) {\n        debug(`Colliding files:${getFileList(\"          \")}`);\n      }\n\n      let { overwrite } = await ctx.prompt({\n        name: \"overwrite\",\n        type: \"confirm\",\n        label: title(\"overwrite\"),\n        message:\n          `Your project directory contains files that will be overwritten by\\n` +\n          `             this template (you can force with \\`--overwrite\\`)\\n\\n` +\n          `             Files that would be overwritten:` +\n          `${getFileList(\"               \")}\\n\\n` +\n          `             Do you wish to continue?\\n` +\n          `             `,\n        initial: false,\n      });\n      if (!overwrite) {\n        throw new Error(\"Exiting to avoid overwriting files\");\n      }\n    }\n  }\n\n  await cp(ctx.tempDir, ctx.cwd, {\n    filter(src) {\n      // We never copy .git/ or node_modules/ directories since it's highly\n      // unlikely we want them copied - and because templates are primarily\n      // being pulled from git tarballs which won't have .git/ and shouldn't\n      // have node_modules/\n      let file = stripDirectoryFromPath(ctx.tempDir, src);\n      let isIgnored = IGNORED_TEMPLATE_DIRECTORIES.includes(file);\n      if (isIgnored) {\n        if (ctx.debug) {\n          debug(`Skipping copy of ${file} directory from template`);\n        }\n        return false;\n      }","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/remix-run/react-router/blob/6beaca39526d5716c3c112ebb0782765baa5a9ce/packages/create-react-router/index.ts#L397-L433","documentation":"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.","triggerScenarios":"Declining the overwrite confirmation prompt after the CLI listed files in the target directory that the template would overwrite.","commonSituations":"Intentional cancel after seeing the collision list; users realizing mid-scaffold they picked the wrong directory.","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"],"exampleFix":"# before: prompted, answered no -> abort\nnpx create-react-router ./existing-dir\n\n# after: decide up front\nnpx create-react-router ./existing-dir --overwrite","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await createReactRouter(args);\n} catch (e) {\n  if ((e as Error).message === \"Exiting to avoid overwriting files\") {\n    // Deliberate user cancellation — exit cleanly, existing files are untouched\n    process.exit(0);\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["cli","interactive","overwrite","abort"],"backgroundTag":"user-cancelled-operation","analyzedSha":"6beaca39526d5716c3c112ebb0782765baa5a9ce","analyzedAt":"2026-08-18T18:04:14.938Z","contentChangedAt":"2026-08-18T18:04:14.938Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}