{"record":{"id":"b68a138095a05174","repo":"payloadcms/payload","slug":"invalid-template-given","errorCode":null,"errorMessage":"Invalid template given","messagePattern":"Invalid template given","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/create-payload-app/src/lib/parse-template.ts","lineNumber":13,"sourceCode":"import * as p from '@clack/prompts'\n\nimport type { CliArgs, ProjectTemplate } from '../types.js'\n\nexport async function parseTemplate(\n  args: CliArgs,\n  validTemplates: ProjectTemplate[],\n): Promise<ProjectTemplate | undefined> {\n  if (args['--template']) {\n    const templateName = args['--template']\n    const template = validTemplates.find((t) => t.name === templateName)\n    if (!template) {\n      throw new Error('Invalid template given')\n    }\n    return template\n  }\n\n  const response = await p.select<{ label: string; value: string }[], string>({\n    message: 'Choose project template',\n    options: validTemplates.map((p) => {\n      return {\n        label: p.name,\n        value: p.name,\n      }\n    }),\n  })\n  if (p.isCancel(response)) {\n    process.exit(0)\n  }\n\n  const template = validTemplates.find((t) => t.name === response)","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/create-payload-app/src/lib/parse-template.ts#L1-L31","documentation":"parseTemplate throws when the --template CLI flag is set but its value does not match any ProjectTemplate.name in the validTemplates list passed to the function. The match is exact (===), so casing, dashes, and slashes must match precisely.","triggerScenarios":"Invoking create-payload-app with --template <name> where <name> is misspelled, uses wrong casing, or refers to a template removed/renamed in the installed create-payload-app version.","commonSituations":"Typo in the template name (e.g. 'blank' vs 'blank-ts'); using a template name from docs for a newer version while running an older CLI; copying a value with surrounding whitespace or quotes.","solutions":["Run create-payload-app without --template and pick from the interactive prompt to see the exact valid names.","Check the installed create-payload-app version's template list (its templates index) and use the exact name string.","Update create-payload-app to the latest version if the template exists in newer releases.","Verify there are no trailing spaces or mismatched casing in the --template argument."],"exampleFix":"// before\n$ npx create-payload-app my-app --template Blanks\n\n// after\n$ npx create-payload-app my-app --template blank","handlingStrategy":"validation","validationCode":"import { validTemplates } from './templates.js' // the CLI's template list\n\nfunction assertValidTemplate(name: string) {\n  if (!validTemplates.some((t) => t.name === name)) {\n    throw new Error(\n      `Unknown template '${name}'. Valid: ${validTemplates.map((t) => t.name).join(', ')}`,\n    )\n  }\n}\nassertValidTemplate(process.argv.includes('--template') ? process.argv[process.argv.indexOf('--template') + 1] : '')","typeGuard":"const templateNames = ['blank', 'blank-tanstack', 'website'] as const\ntype TemplateName = (typeof templateNames)[number]\nfunction isTemplateName(x: string): x is TemplateName {\n  return (templateNames as readonly string[]).includes(x)\n}","tryCatchPattern":"try {\n  await parseTemplate(args, validTemplates)\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid template given') {\n    console.error(`Available templates: ${validTemplates.map((t) => t.name).join(', ')}`)\n  }\n  throw e\n}","preventionTips":["Always source the --template value from the CLI's own template list.","Update create-payload-app before using a template from recent docs.","Avoid hardcoding template names in scripts."],"tags":["create-payload-app","cli","validation","config"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}