{"record":{"id":"450c11195da7d5c0","repo":"twentyhq/twenty","slug":"directory-appdirectory-already-exists-and-is-no","errorCode":null,"errorMessage":"Directory ${appDirectory} already exists and is not empty","messagePattern":"Directory (.+?) already exists and is not empty","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/create-twenty-app/src/create-app.command.ts","lineNumber":227,"sourceCode":"      options.displayName?.trim() || convertToLabel(appName);\n\n    const appDescription = (options.description ?? '').trim();\n\n    const appDirectory = options.directory\n      ? path.join(CURRENT_EXECUTION_DIRECTORY, options.directory)\n      : path.join(CURRENT_EXECUTION_DIRECTORY, kebabCase(appName));\n\n    return { appName, appDisplayName, appDirectory, appDescription };\n  }\n\n  private async validateDirectory(appDirectory: string): Promise<void> {\n    if (!(await fs.pathExists(appDirectory))) {\n      return;\n    }\n\n    const files = await fs.readdir(appDirectory);\n    if (files.length > 0) {\n      throw new Error(\n        `Directory ${appDirectory} already exists and is not empty`,\n      );\n    }\n  }\n\n  private logPlan({\n    appName,\n    appDisplayName,\n    appDescription,\n    appDirectory,\n  }: {\n    appName: string;\n    appDisplayName: string;\n    appDescription: string;\n    appDirectory: string;\n  }): void {\n    console.log(chalk.blue('\\nCreating Twenty Application\\n'));\n    console.log(chalk.white(`  Name:           ${appName}`));","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/create-twenty-app/src/create-app.command.ts#L209-L245","documentation":"Thrown by the create-twenty-app scaffolder's validateDirectory guard before writing any files. It refuses to generate a project into a directory that already exists and contains at least one entry, to prevent silently overwriting or interleaving with existing content. An empty existing directory is allowed; any non-empty one is not.","triggerScenarios":"Running `npx create-twenty-app` (or the package's bin) when the resolved target directory — either the explicit --directory option or path.join(cwd, kebabCase(appName)) — already holds files. fs.pathExists returns true and fs.readdir yields a non-empty array.","commonSituations":"Re-running the scaffolder after a failed/partial earlier attempt left files behind; choosing a default name like my-twenty-app in a folder where another scaffold already landed; pointing --directory at an existing project root; IDE created a .DS_Store or .git keeping the dir non-empty.","solutions":["Pick a different app name (or pass --directory ./new-folder) so the resolved path is empty or absent.","Move or delete the existing directory contents: rm -rf <appDirectory> then re-run.","If you intend to regenerate into the same folder, empty it first but confirm nothing valuable remains.","Check for hidden files (ls -la <appDirectory>) — even one hidden entry trips the guard."],"exampleFix":"// before\n$ npx create-twenty-app   # fails: ./my-twenty-app already has files\n\n// after — point at a fresh directory\n$ npx create-twenty-app --directory my-twenty-app-2","handlingStrategy":"validation","validationCode":"import fs from 'fs-extra';\nimport path from 'path';\n\nasync function assertDirectoryEmpty(target: string): Promise<void> {\n  if (!(await fs.pathExists(target))) return;\n  const files = await fs.readdir(target);\n  if (files.length > 0) {\n    throw new Error(`Refusing to scaffold: '${target}' is not empty (${files.length} entries).`);\n  }\n}\n\n// run before invoking the scaffolder\nawait assertDirectoryEmpty(path.resolve(process.cwd(), 'my-twenty-app'));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Let the scaffolder derive the directory from a unique app name rather than reusing an existing folder.","Before re-running after a failure, remove the partial output directory entirely.","Check for hidden files (ls -la) — a single .DS_Store/.git will trip the guard.","In CI, always scaffold into a fresh temp directory."],"tags":["cli","filesystem","scaffolding"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}