vercel/turborepo · warning · GeneratorError

config_directory_already_exists

config_directory_already_exists

Error message

Generator config directory already exists at ${configDirectory}

What it means

setup-from-template creates the turbo/generators directory at your project root from an embedded template. It throws this GeneratorError with code config_directory_already_exists when that directory already exists, so it never overwrites your generator configs. The same function also rejects unknown template names with the same error code.

Solutions

  1. If the existing turbo/generators content is disposable, remove or rename it and run setup again
  2. If you want to keep it, skip setup and add the new generator files manually into turbo/generators
  3. Inspect the existing directory first so you do not delete custom plopfiles by accident

Example fix

# before: directory already present
mv turbo/generators turbo/generators.bak  # keep a backup
# then re-run setup
npm exec turbo gen
# after: restore your custom generators into the new directory if needed
cp turbo/generators.bak/config.ts turbo/generators/config.ts
Defensive patterns

Strategy: validation

Validate before calling

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

// check before setup so existing generator configs are never clobbered
const configDirectory = path.join(repoRoot, "turbo", "generators");
if (await fs.pathExists(configDirectory)) {
  throw new Error(`Generator config directory already exists at ${configDirectory}`);
}

Type guard

async function hasGeneratorConfig(repoRoot: string): Promise<boolean> {
  return fs.pathExists(path.join(repoRoot, "turbo", "generators"));
}

Try / catch

try {
  await setupFromTemplate({ project, template });
} catch (err) {
  if (err instanceof GeneratorError && err.type === "config_directory_already_exists") {
    // keep existing configs; skip setup instead of failing the whole flow
    console.warn("Generator config already present; skipping template setup.");
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: You run the setup flow (for example turbo gen onboarding) in a repository that already has a turbo/generators folder. fs.pathExists(configDirectory) is true, so it throws before writing any template file.

Common situations: Running the generator setup twice. A teammate already added custom generators. A template config committed earlier under turbo/generators.

Related errors


AI-assisted analysis of vercel/turborepo@f9245100cf (2026-08-17). Data as JSON: /api/errors/73e15451b5383708. Report an issue: GitHub.

Appendix: 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 f9245100cf)