facebook/docusaurus · error · Error
Directory already exists at path=${dest}!
Error message
Directory already exists at path=${dest}! What it means
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.
Source
Thrown at packages/create-docusaurus/src/index.ts:266
rootDir: string,
): Promise<string> {
async function validateSiteName(siteName: string) {
if (!siteName) {
return 'A website name is required.';
}
const dest = path.resolve(rootDir, siteName);
if (siteName === '.' && (await fs.readdir(dest)).length > 0) {
return logger.interpolate`Directory not empty at path=${dest}!`;
}
if (siteName !== '.' && (await pathExists(dest))) {
return logger.interpolate`Directory already exists at path=${dest}!`;
}
return true;
}
if (reqName) {
const res = await validateSiteName(reqName);
if (typeof res === 'string') {
throw new Error(res);
}
return reqName;
}
const {siteName} = (await prompts(
{
type: 'text',
name: 'siteName',
message: 'What should we name this site?',
initial: 'website',
validate: validateSiteName,
},
{
onCancel() {
logger.error('A website name is required.');
process.exit(1);
},
},
)) as {siteName: string};View on GitHub (pinned to 3f483e80e3)
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).
Example fix
# before npx create-docusaurus website # website/ already exists # after (option A) rm -rf website && npx create-docusaurus website # after (option B) npx create-docusaurus my-new-site
Defensive patterns
Strategy: validation
Validate before calling
import path from 'node:path';
import {pathExists} from './utils.js';
async function assertDestFree(rootDir: string, siteName: string) {
if (siteName === '.') return;
const dest = path.resolve(rootDir, siteName);
if (await pathExists(dest)) {
throw new Error(`Directory already exists at path=${dest}!`);
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid package manager choice ${packageManager}. Must be on
- Invalid command: ${command}
- Copying Docusaurus template name=${source.template.name} fai
- Copying local template path=${source.path} failed!
- Failed to update package.json.
AI-assisted analysis of facebook/docusaurus@3f483e80e3 (2026-08-12).
Data as JSON: /api/errors/528b1f73cdc3f04d.
Report an issue: GitHub.