{"record":{"id":"d9fb20c7a2056104","repo":"marmelab/react-admin","slug":"a-directory-named-projectname-already-exists-in","errorCode":null,"errorMessage":"A directory named ${projectName} already exists in the current directory. Please choose a different name.","messagePattern":"A directory named (.+?) already exists in the current directory\\. Please choose a different name\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/create-react-admin/src/generateProject.ts","lineNumber":209,"sourceCode":"    const packageJsonPath = path.join(\n        __dirname,\n        '../templates',\n        template,\n        'package.json'\n    );\n    if (fs.existsSync(packageJsonPath)) {\n        const packageJson = fs.readFileSync(packageJsonPath, 'utf-8');\n        return JSON.parse(packageJson);\n    }\n    return {};\n};\n\nconst initializeProjectDirectory = (projectName: string) => {\n    let projectDirectory = process.cwd();\n\n    if (path.dirname(projectDirectory) !== projectName) {\n        if (fs.existsSync(path.join(process.cwd(), projectName))) {\n            throw new Error(\n                `A directory named ${projectName} already exists in the current directory. Please choose a different name.`\n            );\n        }\n        projectDirectory = path.join(process.cwd(), projectName);\n        fs.mkdirSync(projectDirectory);\n    }\n    return projectDirectory;\n};\n\nconst copyDirectoryFiles = (\n    source: string,\n    destination: string,\n    excludes?: string[]\n) => {\n    fsExtra.copySync(\n        source,\n        destination,\n        excludes && excludes.length","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/create-react-admin/src/generateProject.ts#L191-L227","documentation":"create-react-admin refuses to scaffold into an existing directory to avoid clobbering user files. In initializeProjectDirectory, if fs.existsSync finds a directory (or file) named projectName in the current working directory, it throws immediately instead of overwriting. The check is skipped only when the parent directory path already equals projectName.","triggerScenarios":"Running `npx create-react-admin my-admin` (or the equivalent projectDirectory flow) when ./my-admin already exists in the cwd, e.g. from a previous partial or complete scaffold run.","commonSituations":"Re-running the generator after a failed install left a half-created directory; forgetting a previous run already created the folder; wanting to regenerate an existing app without deleting it first.","solutions":["Choose a different project name on the command line, e.g. `npx create-react-admin my-admin-v2`.","Remove or rename the existing directory if it is safe to delete: `rm -rf my-admin` then re-run the generator.","Run the command from a different directory that does not contain a folder with that name.","If the existing directory is a previous incomplete run you want to keep work from, move it aside: `mv my-admin my-admin.bak`."],"exampleFix":"// before (shell)\nnpx create-react-admin my-admin\n// Error: A directory named my-admin already exists...\n\n// after (shell)\nrm -rf my-admin  # or pick another name\nnpx create-react-admin my-admin","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst path = require('path');\nif (fs.existsSync(path.join(process.cwd(), projectName))) {\n  throw new Error(`Directory ${projectName} already exists; pick another name or remove it first.`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  createProject(projectName);\n} catch (e) {\n  if (e.message.includes('already exists')) {\n    console.error(`Name conflict: ${projectName}. Use a different name or delete the existing folder.`);\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Check the target directory with ls before scaffolding.","Use unique, timestamped project names for experiments.","Clean up failed scaffold attempts immediately.","Run the generator from a dedicated workspace directory."],"tags":["filesystem","cli","scaffolding","name-conflict"],"backgroundTag":"directory-already-exists","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}