{"record":{"id":"528b1f73cdc3f04d","repo":"facebook/docusaurus","slug":"directory-already-exists-at-path-dest","errorCode":null,"errorMessage":"Directory already exists at path=${dest}!","messagePattern":"Directory already exists at path=(.+?)!","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/create-docusaurus/src/index.ts","lineNumber":266,"sourceCode":"  rootDir: string,\n): Promise<string> {\n  async function validateSiteName(siteName: string) {\n    if (!siteName) {\n      return 'A website name is required.';\n    }\n    const dest = path.resolve(rootDir, siteName);\n    if (siteName === '.' && (await fs.readdir(dest)).length > 0) {\n      return logger.interpolate`Directory not empty at path=${dest}!`;\n    }\n    if (siteName !== '.' && (await pathExists(dest))) {\n      return logger.interpolate`Directory already exists at path=${dest}!`;\n    }\n    return true;\n  }\n  if (reqName) {\n    const res = await validateSiteName(reqName);\n    if (typeof res === 'string') {\n      throw new Error(res);\n    }\n    return reqName;\n  }\n  const {siteName} = (await prompts(\n    {\n      type: 'text',\n      name: 'siteName',\n      message: 'What should we name this site?',\n      initial: 'website',\n      validate: validateSiteName,\n    },\n    {\n      onCancel() {\n        logger.error('A website name is required.');\n        process.exit(1);\n      },\n    },\n  )) as {siteName: string};","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/create-docusaurus/src/index.ts#L248-L284","documentation":"Thrown by getSiteName() in create-docusaurus when a non-empty site name (anything other than '.') is supplied and the resolved destination directory already exists on disk. The validateSiteName helper returns this message as a string, and when a name is provided via the CLI (reqName) the string is turned into a thrown Error. Docusaurus refuses to overwrite an existing project directory to avoid clobbering user files.","triggerScenarios":"Running `npx create-docusaurus existing-dir` where existing-dir already exists; passing a name that resolves to an existing folder under rootDir; re-running init in a directory where a previous partial run left the folder behind.","commonSituations":"Re-running create-docusaurus after a failed earlier attempt left the target folder; choosing a common name like 'website' or 'docs' that collides with an existing folder; CI re-running on a checked-out workspace that already contains the folder.","solutions":["Pick a different site name that does not yet exist.","Delete or move the existing directory, then re-run: rm -rf existing-dir.","Use '.' as the name to scaffold into the current directory, but only if that directory is empty (a separate 'Directory not empty' guard applies)."],"exampleFix":"# before\nnpx create-docusaurus website   # website/ already exists\n# after (option A)\nrm -rf website && npx create-docusaurus website\n# after (option B)\nnpx create-docusaurus my-new-site","handlingStrategy":"validation","validationCode":"import path from 'node:path';\nimport {pathExists} from './utils.js';\nasync function assertDestFree(rootDir: string, siteName: string) {\n  if (siteName === '.') return;\n  const dest = path.resolve(rootDir, siteName);\n  if (await pathExists(dest)) {\n    throw new Error(`Directory already exists at path=${dest}!`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the destination directory before invoking init, or pick a unique name.","In CI, scaffold into a fresh temp dir each run.","Wrap init in a script that cleans a partial target on failure."],"tags":["create-docusaurus","cli","filesystem","validation"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}