{"record":{"id":"051ea3b9a41821cd","repo":"mastra-ai/mastra","slug":"a-file-or-directory-named-projectname-already","errorCode":null,"errorMessage":"A file or directory named \"${projectName}\" already exists. Please choose a different name.","messagePattern":"A file or directory named \"(.+?)\" already exists\\. Please choose a different name\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/create/create.ts","lineNumber":245,"sourceCode":"  projectName: string | undefined,\n  options: CreateCommandOptions,\n  dependencies: Pick<CreateOptions, 'analytics' | 'resolveVersionTag'> = {},\n): Promise<void> {\n  const normalized = normalizeCreateCommandOptions(projectName, options);\n  await create({ ...normalized, ...dependencies });\n}\n\nexport const create = async (args: CreateOptions): Promise<void> => {\n  const options = normalizeDirectCreateOptions(args);\n  const mode = validateCreateOptionConflicts(options);\n  const invocationCwd = process.cwd();\n\n  const rawProjectName = options.projectName ?? (await promptForProjectName());\n  const projectName = validateProjectName(rawProjectName);\n  const targetPath = path.resolve(invocationCwd, projectName);\n\n  if (fsSync.existsSync(targetPath)) {\n    throw new Error(`A file or directory named \"${projectName}\" already exists. Please choose a different name.`);\n  }\n\n  const analytics = args.analytics ?? getAnalytics();\n  let llmProvider = options.llmProvider;\n  let llmApiKey = options.llmApiKey;\n  let providerSelectionMethod: 'cli_args' | 'interactive' | undefined;\n  let observabilityEnabled = false;\n  let platformSetupController: AbortController | undefined;\n  let platformSetupPromise: Promise<PlatformSetupResult> | undefined;\n\n  if (mode === 'managed') {\n    const providerProvidedByCli = llmProvider !== undefined;\n    if (llmProvider) {\n      providerSelectionMethod = 'cli_args';\n    } else {\n      llmProvider = await promptForProvider();\n      providerSelectionMethod = 'interactive';\n    }","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/create/create.ts#L227-L263","documentation":"`create` in packages/cli/src/commands/create/create.ts:244 checks `fsSync.existsSync(targetPath)` for the resolved project directory and throws if any file or directory already occupies it. This prevents clobbering existing content — the scaffolder only writes into a fresh path. Note the interactive prompt validates this too, but the explicit projectName CLI argument path only hits this throw.","triggerScenarios":"`mastra create my-app` when ./my-app already exists (previous scaffold, empty dir, or stray file); running create twice in the same directory; a file (not dir) with the target name exists.","commonSituations":"Re-running a failed/partial create after cleanup didn't remove the folder; colliding with a common name like `app` or `server` in a crowded workspace; leftover staging output from an interrupted run.","solutions":["Choose a different project name: `mastra create my-app-2`","Remove or rename the existing file/directory if it's no longer needed: `mv my-app my-app.bak`","Inspect the existing path first (`ls my-app`) to confirm it's safe to delete","Run the command from a different parent directory"],"exampleFix":"// before\nmastra create my-app   # ./my-app exists\n// after\nrm -rf my-app          # or rename it\nmastra create my-app","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nimport path from 'node:path';\nconst target = path.resolve(process.cwd(), projectName);\nif (fs.existsSync(target)) {\n  throw new Error(`\"${projectName}\" already exists in ${process.cwd()}; pick another name or remove it`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await create({ projectName });\n} catch (error) {\n  if (error instanceof Error && error.message.includes('already exists')) {\n    const alt = `${projectName}-${Date.now()}`;\n    console.error(`Path taken; retrying as ${alt}`);\n    await create({ projectName: alt });\n  } else throw error;\n}","preventionTips":["Check fs.existsSync on the target path before invoking create","Use unique, timestamped names in CI to avoid rerun collisions","Clean up partially created projects before re-running create","Note the interactive prompt also blocks existing directories — the throw mainly guards the CLI-arg path"],"tags":["cli","filesystem","conflict","already-exists"],"backgroundTag":"path-already-exists","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}