{"record":{"id":"78619794f0525bbd","repo":"remix-run/remix","slug":"rmx-target-directory-not-empty","errorCode":"RMX_TARGET_DIRECTORY_NOT_EMPTY","errorMessage":"Target directory is not empty","messagePattern":"Target directory is not empty","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/lib/errors.ts","lineNumber":132,"sourceCode":"    title: 'Route-map loader returned invalid JSON',\n    fix: 'Check app/routes.ts and make sure route-map loading does not write extra output.',\n  },\n  routeMapLoaderSignal: {\n    code: 'RMX_ROUTE_MAP_LOADER_SIGNAL',\n    title: 'Route-map loader exited from a signal',\n    fix: 'Check app/routes.ts for side effects or runtime issues and try again.',\n  },\n  routeOwnerPlanUnresolved: {\n    code: 'RMX_ROUTE_OWNER_PLAN_UNRESOLVED',\n    title: 'Could not resolve a route owner plan',\n  },\n  routesFileNotFound: {\n    code: 'RMX_ROUTES_FILE_NOT_FOUND',\n    title: 'Could not find app/routes.ts',\n    fix: 'Run this command inside a Remix app that has app/routes.ts.',\n  },\n  targetDirectoryNotEmpty: {\n    code: 'RMX_TARGET_DIRECTORY_NOT_EMPTY',\n    title: 'Target directory is not empty',\n    fix: 'Re-run with --force to continue.',\n  },\n  targetPathNotDirectory: {\n    code: 'RMX_TARGET_PATH_NOT_DIRECTORY',\n    title: 'Target path is not a directory',\n    fix: 'Choose a directory path for the new app target.',\n  },\n  unexpectedExtraArgument: {\n    code: 'RMX_UNEXPECTED_ARGUMENT',\n    title: 'Unexpected extra argument',\n    fix: 'Remove the extra argument or run the command with --help.',\n  },\n  unknownArgument: {\n    code: 'RMX_UNKNOWN_ARGUMENT',\n    title: 'Unknown argument',\n    fix: 'Run the command with --help to see supported arguments.',\n  },","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/cli/src/lib/errors.ts#L114-L150","documentation":"The CLI refuses to scaffold or write into a target directory that already contains files, to avoid overwriting existing work. The error includes an explicit escape hatch: re-running with --force proceeds anyway.","triggerScenarios":"Running a create/init-style command with a target directory that has existing entries, without passing --force.","commonSituations":"Re-running a scaffold command after a partial first run, creating an app into `.` inside a non-empty folder, or a leftover template checkout in the target.","solutions":["Re-run the command with --force if overwriting is acceptable.","Point the command at a fresh empty directory.","Clean out or move the existing contents of the target directory and re-run without --force."],"exampleFix":"# before\nremix init ./my-app # directory not empty\n\n# after\nremix init ./my-app --force","handlingStrategy":"validation","validationCode":"import { readdir } from 'node:fs/promises'\n\nlet entries = await readdir(targetDir).catch(() => [])\nlet isEmpty = entries.length === 0\n// pass --force only when !isEmpty is intended","typeGuard":null,"tryCatchPattern":"try {\n  await scaffold(target)\n} catch (error) {\n  if (error.code === 'RMX_TARGET_DIRECTORY_NOT_EMPTY' && allowOverwrite) {\n    await scaffold(target, { force: true })\n  }\n}","preventionTips":["Check directory emptiness before scaffolding.","Only pass --force when overwrite is safe."],"tags":["cli","filesystem","scaffold"],"backgroundTag":"directory-not-empty-guard","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}