vercel/turborepo · error · GeneratorError

Generator config directory already exists at ${configDirecto

Error message

Generator config directory already exists at ${configDirectory}

What it means

Thrown by setupFromTemplate() in @turbo/gen when scaffolding an embedded 'simple-ts' or 'simple-js' generator template. The function only writes its files into a fresh <projectRoot>/turbo/generators directory, so it refuses to run if that directory already exists, wrapping the failure in a GeneratorError of type config_directory_already_exists.

Source

Thrown at packages/turbo-gen/src/utils/setup-from-template.ts:25

export async function setupFromTemplate({
  project,
  template
}: {
  project: Project;
  template: "ts" | "js";
}) {
  const configDirectory = path.join(project.paths.root, "turbo", "generators");

  const templateKey = `simple-${template}`;
  const embeddedTemplate = TEMPLATES[templateKey];
  if (!embeddedTemplate) {
    throw new GeneratorError(`Unknown template "${templateKey}"`, {
      type: "config_directory_already_exists"
    });
  }

  if (await fs.pathExists(configDirectory)) {
    throw new GeneratorError(
      `Generator config directory already exists at ${configDirectory}`,
      { type: "config_directory_already_exists" }
    );
  }

  for (const file of embeddedTemplate.files) {
    const filePath = path.join(configDirectory, file.relativePath);
    await fs.outputFile(filePath, file.content);
  }
}

View on GitHub (pinned to 9f94a7d215)

Solutions

  1. Delete or rename the existing <root>/turbo/generators directory, then re-run the command
  2. If you want to keep existing generators, skip the embedded template setup and add the new generator files manually under turbo/generators
  3. Run the command against a different project root that does not yet have a turbo/generators directory

Example fix

# before: turbo/generators already exists, command fails
rm -rf turbo/generators        # or: mv turbo/generators turbo/generators.bak

# after: re-run the scaffold command
npx turbo gen init
Defensive patterns

Strategy: validation

Validate before calling

import fs from "fs-extra";
import path from "node:path";

const configDir = path.join(project.paths.root, "turbo", "generators");
if (await fs.pathExists(configDir)) {
  // choose: skip scaffold, or prompt to overwrite
} else {
  await setupFromTemplate({ project, template });
}

Type guard

import { GeneratorError } from "@turbo/gen/utils/error";

function isConfigDirExistsError(e: unknown): boolean {
  return e instanceof GeneratorError && e.type === "config_directory_already_exists";
}

Try / catch

try {
  await setupFromTemplate({ project, template });
} catch (e) {
  if (e instanceof GeneratorError && e.type === "config_directory_already_exists") {
    // prompt user or skip; message names the existing directory
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Calling setupFromTemplate({ project, template }) for a project whose path.join(project.paths.root, 'turbo', 'generators') already exists on disk (even if empty) — e.g. running the generator init/scaffold flow twice in the same monorepo, or a checkout that already contains turbo/generators/config.json or custom generators.

Common situations: Re-running `turbo gen init` after a previous run; a repo that already has custom plop generators under turbo/generators; scaffolding into a template project that pre-creates the directory.

Related errors


AI-assisted analysis of vercel/turborepo@9f94a7d215 (2026-08-16). Data as JSON: /api/errors/e5048b31f8d842ec. Report an issue: GitHub.