remix-run/remix · error · CliError

RMX_TARGET_DIRECTORY_NOT_EMPTY

RMX_TARGET_DIRECTORY_NOT_EMPTY

Error message

Target directory is not empty

What it means

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.

Source

Thrown at packages/cli/src/lib/errors.ts:132

    title: 'Route-map loader returned invalid JSON',
    fix: 'Check app/routes.ts and make sure route-map loading does not write extra output.',
  },
  routeMapLoaderSignal: {
    code: 'RMX_ROUTE_MAP_LOADER_SIGNAL',
    title: 'Route-map loader exited from a signal',
    fix: 'Check app/routes.ts for side effects or runtime issues and try again.',
  },
  routeOwnerPlanUnresolved: {
    code: 'RMX_ROUTE_OWNER_PLAN_UNRESOLVED',
    title: 'Could not resolve a route owner plan',
  },
  routesFileNotFound: {
    code: 'RMX_ROUTES_FILE_NOT_FOUND',
    title: 'Could not find app/routes.ts',
    fix: 'Run this command inside a Remix app that has app/routes.ts.',
  },
  targetDirectoryNotEmpty: {
    code: 'RMX_TARGET_DIRECTORY_NOT_EMPTY',
    title: 'Target directory is not empty',
    fix: 'Re-run with --force to continue.',
  },
  targetPathNotDirectory: {
    code: 'RMX_TARGET_PATH_NOT_DIRECTORY',
    title: 'Target path is not a directory',
    fix: 'Choose a directory path for the new app target.',
  },
  unexpectedExtraArgument: {
    code: 'RMX_UNEXPECTED_ARGUMENT',
    title: 'Unexpected extra argument',
    fix: 'Remove the extra argument or run the command with --help.',
  },
  unknownArgument: {
    code: 'RMX_UNKNOWN_ARGUMENT',
    title: 'Unknown argument',
    fix: 'Run the command with --help to see supported arguments.',
  },

View on GitHub (pinned to 9696913134)

Solutions

  1. Re-run the command with --force if overwriting is acceptable.
  2. Point the command at a fresh empty directory.
  3. Clean out or move the existing contents of the target directory and re-run without --force.

Example fix

# before
remix init ./my-app # directory not empty

# after
remix init ./my-app --force
Defensive patterns

Strategy: validation

Validate before calling

import { readdir } from 'node:fs/promises'

let entries = await readdir(targetDir).catch(() => [])
let isEmpty = entries.length === 0
// pass --force only when !isEmpty is intended

Try / catch

try {
  await scaffold(target)
} catch (error) {
  if (error.code === 'RMX_TARGET_DIRECTORY_NOT_EMPTY' && allowOverwrite) {
    await scaffold(target, { force: true })
  }
}

Prevention

When it happens

Trigger: Running a create/init-style command with a target directory that has existing entries, without passing --force.

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

Related errors


AI-assisted analysis of remix-run/remix@9696913134 (2026-08-27). Data as JSON: /api/errors/78619794f0525bbd. Report an issue: GitHub.