marmelab/react-admin · error · Error

A directory named ${projectName} already exists in the curre

Error message

A directory named ${projectName} already exists in the current directory. Please choose a different name.

What it means

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.

Source

Thrown at packages/create-react-admin/src/generateProject.ts:209

    const packageJsonPath = path.join(
        __dirname,
        '../templates',
        template,
        'package.json'
    );
    if (fs.existsSync(packageJsonPath)) {
        const packageJson = fs.readFileSync(packageJsonPath, 'utf-8');
        return JSON.parse(packageJson);
    }
    return {};
};

const initializeProjectDirectory = (projectName: string) => {
    let projectDirectory = process.cwd();

    if (path.dirname(projectDirectory) !== projectName) {
        if (fs.existsSync(path.join(process.cwd(), projectName))) {
            throw new Error(
                `A directory named ${projectName} already exists in the current directory. Please choose a different name.`
            );
        }
        projectDirectory = path.join(process.cwd(), projectName);
        fs.mkdirSync(projectDirectory);
    }
    return projectDirectory;
};

const copyDirectoryFiles = (
    source: string,
    destination: string,
    excludes?: string[]
) => {
    fsExtra.copySync(
        source,
        destination,
        excludes && excludes.length

View on GitHub (pinned to 051f511bb0)

Solutions

  1. Choose a different project name on the command line, e.g. `npx create-react-admin my-admin-v2`.
  2. Remove or rename the existing directory if it is safe to delete: `rm -rf my-admin` then re-run the generator.
  3. Run the command from a different directory that does not contain a folder with that name.
  4. If the existing directory is a previous incomplete run you want to keep work from, move it aside: `mv my-admin my-admin.bak`.

Example fix

// before (shell)
npx create-react-admin my-admin
// Error: A directory named my-admin already exists...

// after (shell)
rm -rf my-admin  # or pick another name
npx create-react-admin my-admin
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const path = require('path');
if (fs.existsSync(path.join(process.cwd(), projectName))) {
  throw new Error(`Directory ${projectName} already exists; pick another name or remove it first.`);
}

Try / catch

try {
  createProject(projectName);
} catch (e) {
  if (e.message.includes('already exists')) {
    console.error(`Name conflict: ${projectName}. Use a different name or delete the existing folder.`);
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30). Data as JSON: /api/errors/d9fb20c7a2056104. Report an issue: GitHub.