mastra-ai/mastra · error · Error

No template selected

Error message

No template selected

What it means

`resolveTemplate` in packages/cli/src/commands/create/create.ts:731 throws 'No template selected' when the `template` argument is neither `true` (interactive selection) nor a usable string. This is a defensive guard for the impossible-in-CLI case where template mode was requested but the value resolved to a non-string, non-boolean (e.g. undefined via the programmatic API while mode was computed as 'template').

Source

Thrown at packages/cli/src/commands/create/create.ts:732

    mcp: [],
    tools: [],
    networks: [],
    workflows: [],
  };
}

async function resolveTemplate(mode: Exclude<CreateMode, 'empty'>, template?: string | boolean): Promise<Template> {
  if (mode === 'managed') return DEFAULT_TEMPLATE;

  if (template === true) {
    const templates = await loadTemplates();
    const selected = await runCreatePrompt(signal => selectTemplate(templates, { signal }));
    if (!selected) cancelCreate();
    return selected;
  }

  if (typeof template !== 'string') {
    throw new Error('No template selected');
  }

  const githubUrl = parseGitHubRepositoryUrl(template);
  if (githubUrl) {
    const spinner = p.spinner();
    spinner.start('Validating GitHub repository...');
    const validation = await validateGitHubProject(githubUrl);
    if (!validation.isValid) {
      spinner.stop('Validation failed');
      p.log.error('This does not appear to be a valid Mastra project:');
      validation.errors.forEach(error => p.log.error(`  - ${error}`));
      throw new Error('Invalid Mastra project');
    }
    spinner.stop('Valid Mastra project ✓');
    return createFromGitHubUrl(githubUrl);
  }
  if (looksLikeGitHubUrl(template)) {
    throw new Error('Invalid GitHub repository URL. Use https://github.com/<owner>/<repository>.');

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Ensure a template slug/URL string is actually passed: `--template template-agent-harness`
  2. When scripting the API, validate the template value is a non-empty string before calling create()
  3. Use `--template` with no value to get interactive selection instead of an undefined value
  4. Check the env/config source feeding the template argument for typos or unset values

Example fix

// before
await create({ template: process.env.TEMPLATE }); // undefined -> throws
// after
const template = process.env.TEMPLATE;
if (typeof template !== 'string' || template.length === 0) {
  throw new Error('TEMPLATE env var must be set to a template slug or GitHub URL');
}
await create({ template });
Defensive patterns

Strategy: validation

Validate before calling

function assertTemplateProvided(template: string | boolean | undefined): asserts template is string | boolean {
  if (template === undefined || template === null || template === '') {
    throw new Error('template must be true (interactive) or a non-empty slug/GitHub URL');
  }
}

Type guard

function hasTemplate(t: unknown): t is string | boolean {
  return typeof t === 'string' ? t.length > 0 : typeof t === 'boolean';
}

Try / catch

try {
  await create({ template });
} catch (error) {
  if (error instanceof Error && error.message === 'No template selected') {
    console.error('Template mode was requested but no template value was provided');
  } else throw error;
}

Prevention

When it happens

Trigger: Calling `create()` programmatically with `{ template: <slug from a variable> }` where the variable is undefined/null at runtime, while options.empty is false so the mode resolves to 'template' (e.g. `template: process.env.TEMPLATE` with the env var unset).

Common situations: Scripting the create API with config-driven template slugs that are missing/empty; TS types bypassed via JSON.parse of CLI input; refactors leaving template undefined while still forcing template mode.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/b11d1e1e0ab2f1df. Report an issue: GitHub.