{"record":{"id":"b9d495db137b4e38","repo":"vercel/turborepo","slug":"failed-to-run-generator","errorCode":null,"errorMessage":"Failed to run generator","messagePattern":"Failed to run generator","errorType":"exception","errorClass":"GeneratorError","httpStatus":null,"severity":"error","filePath":"packages/turbo-gen/src/generators/custom.ts","lineNumber":88,"sourceCode":"    await runCustomGenerator({\n      project,\n      generator: selectedGenerator,\n      bypassArgs: opts.args,\n      configPath: opts.config\n    });\n  } catch (err) {\n    // pass any GeneratorErrors through to root\n    if (err instanceof GeneratorError) {\n      throw err;\n    }\n\n    // capture any other errors and throw as GeneratorErrors\n    let message = \"Failed to run generator\";\n    if (err instanceof Error) {\n      message = err.message;\n    }\n\n    throw new GeneratorError(message, {\n      type: \"plop_error_running_generator\"\n    });\n  } finally {\n    if (isOnboarding) {\n      logger.log();\n      logger.info(`Congrats! You just ran your first Turborepo generator`);\n      logger.dimmed(\n        \"Learn more about custom Turborepo generators - https://turborepo.dev/docs/guides/generating-code#custom-generators\"\n      );\n    }\n  }\n\n  logger.log();\n  logger.bold(logger.turboGradient(\">>> Success!\"));\n}\n","sourceCodeStart":70,"sourceCodeEnd":104,"githubUrl":"https://github.com/vercel/turborepo/blob/9f94a7d215b3881942527dd526afa3fc650869d5/packages/turbo-gen/src/generators/custom.ts#L70-L104","documentation":"turbo-gen's custom generator runner executes your plop-based generator config (turbo/generators/config.ts). Any exception escaping that run which is not already a GeneratorError — a throw inside prompts/actions, a missing template file, an invalid action definition — is captured and rethrown as GeneratorError 'Failed to run generator' (type plop_error_running_generator), carrying the underlying error's message.","triggerScenarios":"The generator config throws at runtime during plop execution; an `add`/`addMany` action references a templatePath that does not exist; an unknown action type string; a helper/partial used but never registered; TS/ESM issues that survived the esbuild bundling fallback.","commonSituations":"Hand-written generator configs after refactors move template files without updating paths; installing new deps in the config without adding them to the workspace; typos in action type names like 'modifiy'.","solutions":["Read the GeneratorError message — it is the underlying err.message and names the real fault (usually the missing template path or action type)","Reproduce config-load errors standalone: `npx tsx turbo/generators/config.ts` (or bundle with esbuild) to surface syntax/type errors the CLI swallows","Verify every templatePath is correct relative to the config file (`ls` each referenced path)","Check action types against node-plop's supported set (add, addMany, modify, append, move, copy) and that helpers/partials are registered before use"],"exampleFix":"// turbo/generators/config.ts (before)\nplop.setActionType('scaffold', ...) // typo'd action used below\nactions.push({ type: 'scaffod', ... })\n// after\nactions.push({ type: 'scaffold', ... })","handlingStrategy":"try-catch","validationCode":"import fs from 'node:fs';\n\nfunction templatePathsExist(configDir: string, templatePaths: string[]): boolean {\n  return templatePaths.every((t) => fs.existsSync(`${configDir}/${t}`));\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runCustomGenerator({ project, generator });\n} catch (err) {\n  if (err instanceof GeneratorError && err.type === 'plop_error_running_generator') {\n    // err.message is the underlying cause: log it with full detail and stop — do not blindly retry\n    logger.error(`generator crashed: ${err.message}`);\n    throw err;\n  }\n  throw err;\n}","preventionTips":["Smoke-test generator configs in CI by running them against a scratch directory","Keep template files co-located with the config and reference them with paths relative to the config file","Install every dependency the config imports (only @inquirer/prompts is CLI-provided)"],"tags":["turbo-gen","generator","plop","codemod","templates"],"backgroundTag":"generator-execution-failed","analyzedSha":"9f94a7d215b3881942527dd526afa3fc650869d5","analyzedAt":"2026-08-16T19:47:29.531Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}