{"record":{"id":"b9bbc96aca89f460","repo":"vercel/turborepo","slug":"unknown-template-templatekey","errorCode":null,"errorMessage":"Unknown template \"${templateKey}\"","messagePattern":"Unknown template \"(.+?)\"","errorType":"exception","errorClass":"GeneratorError","httpStatus":null,"severity":"error","filePath":"packages/turbo-gen/src/utils/setup-from-template.ts","lineNumber":19,"sourceCode":"import path from \"node:path\";\nimport type { Project } from \"@turbo/workspaces\";\nimport fs from \"fs-extra\";\nimport { GeneratorError } from \"./error\";\nimport { TEMPLATES } from \"../templates/embedded\";\n\nexport async function setupFromTemplate({\n  project,\n  template\n}: {\n  project: Project;\n  template: \"ts\" | \"js\";\n}) {\n  const configDirectory = path.join(project.paths.root, \"turbo\", \"generators\");\n\n  const templateKey = `simple-${template}`;\n  const embeddedTemplate = TEMPLATES[templateKey];\n  if (!embeddedTemplate) {\n    throw new GeneratorError(`Unknown template \"${templateKey}\"`, {\n      type: \"config_directory_already_exists\"\n    });\n  }\n\n  if (await fs.pathExists(configDirectory)) {\n    throw new GeneratorError(\n      `Generator config directory already exists at ${configDirectory}`,\n      { type: \"config_directory_already_exists\" }\n    );\n  }\n\n  for (const file of embeddedTemplate.files) {\n    const filePath = path.join(configDirectory, file.relativePath);\n    await fs.outputFile(filePath, file.content);\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/vercel/turborepo/blob/9f94a7d215b3881942527dd526afa3fc650869d5/packages/turbo-gen/src/utils/setup-from-template.ts#L1-L36","documentation":"setupFromTemplate materializes the embedded generator templates under turbo/generators, keyed `simple-ts` / `simple-js` from the `template` argument (typed 'ts' | 'js'). If the TEMPLATES map lacks that key, this GeneratorError is thrown — in practice an internal invariant, since the templates ship embedded with @turbo/gen. Hitting it means a broken/partial install, a version-skewed build, or a programmatic caller bypassing the 'ts'|'js' type. (Note: the error's `type` is mislabeled 'config_directory_already_exists'.)","triggerScenarios":"A corrupted or incomplete @turbo/gen / turbo CLI install missing the embedded template files; a custom build where the templates embedding step did not run; calling setupFromTemplate programmatically with a value other than 'ts' or 'js' despite the type annotation.","commonSituations":"Almost exclusively internal: tampered installs, patched node_modules, or downstream forks that regenerate the templates map; ordinary CLI users should not see it.","solutions":["Reinstall cleanly: remove node_modules and lockfile artifacts for the turbo CLI / @turbo/gen and reinstall (`npm i -g turbo@latest` or retry `npx turbo@latest gen init`)","If calling programmatically, pass only 'ts' or 'js' as the template value","If it persists on a clean install, report upstream — include that the error type string is 'config_directory_already_exists', a known mislabel for this branch"],"exampleFix":"// before (programmatic caller)\nsetupFromTemplate({ project, template: 'typescript' as unknown as 'ts' });\n// after\nsetupFromTemplate({ project, template: 'ts' });","handlingStrategy":"type-guard","validationCode":"const SUPPORTED_TEMPLATES = new Set(['ts', 'js']);\n\nfunction isSupportedTemplate(t: string): boolean {\n  return SUPPORTED_TEMPLATES.has(t);\n}\n// programmatic callers: if (!isSupportedTemplate(t)) throw before setupFromTemplate","typeGuard":"function isTemplateKind(t: string): t is 'ts' | 'js' {\n  return t === 'ts' || t === 'js';\n}","tryCatchPattern":"try {\n  await setupFromTemplate({ project, template });\n} catch (err) {\n  if (err instanceof GeneratorError && /Unknown template/.test(err.message)) {\n    // internal invariant broken: reinstall the CLI package cleanly and retry once\n    throw new Error('embedded generator templates missing — reinstall turbo/@turbo/gen');\n  }\n  throw err;\n}","preventionTips":["Pass only 'ts' or 'js' when calling setupFromTemplate programmatically","Avoid patching/forking the embedded templates map without regenerating it in the build","If seen unexpectedly, do a clean reinstall of the turbo CLI before debugging further"],"tags":["turbo-gen","generator","template","internal-error","install"],"backgroundTag":"template-not-found","analyzedSha":"9f94a7d215b3881942527dd526afa3fc650869d5","analyzedAt":"2026-08-16T19:47:29.531Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}