clockworklabs/SpacetimeDB · error · anyhow::Error

Either --template or --lang must be provided in non-interact

Error message

Either --template or --lang must be provided in non-interactive mode

What it means

Non-interactive init cannot ask questions, so it needs either a template reference or an explicit language to know what to scaffold. With neither `--template` nor `--lang` supplied in non-interactive mode, init aborts before creating anything. (Interactive mode instead shows a language/template picker.) Note that `--template` and `--lang` are mutually exclusive — passing both fails a separate validation.

Source

Thrown at crates/cli/src/subcommands/init.rs:762

}

async fn get_template_config_non_interactive(
    options: &InitOptions,
    project_name: String,
    project_path: PathBuf,
) -> anyhow::Result<TemplateConfig> {
    // Check if template is provided
    if let Some(template_str) = options.template.as_ref() {
        // Check if it's a builtin template
        let templates = fetch_templates_list().await?;
        return create_template_config_from_template_str(project_name, project_path, template_str, &templates);
    }

    // No template - require at least one language option
    let server_lang_str = options.lang.clone();

    if server_lang_str.is_none() {
        anyhow::bail!("Either --template or --lang must be provided in non-interactive mode");
    }

    Ok(TemplateConfig {
        project_name,
        project_path,
        template_type: TemplateType::Empty,
        server_lang: parse_server_lang(&server_lang_str)?,
        client_lang: None,
        github_repo: None,
        template_def: None,
        use_local: true,
        native_aot: false,
    })
}

pub fn ensure_empty_directory(_project_name: &str, project_path: &Path, is_server_only: bool) -> anyhow::Result<()> {
    if project_path.exists() {
        if !project_path.is_dir() {

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Add `--lang rust` (or csharp / typescript / cpp)
  2. Add `--template <id>` for a full-stack template, or `--template owner/repo` for a git repo
  3. Run without `--non-interactive` in a real terminal to get the picker

Example fix

# before
spacetime init --non-interactive --project-name my-app

# after
spacetime init --non-interactive --project-name my-app --lang rust
Defensive patterns

Strategy: validation

Validate before calling

# Enforce the non-interactive contract in the wrapper:
if [[ "$NON_INTERACTIVE" == "true" ]]; then
  [[ -n "$PROJECT_NAME" ]] || { echo "need --project-name" >&2; exit 2; }
  [[ -n "$TEMPLATE" || -n "$LANG_ARG" ]] || { echo "need --template or --lang" >&2; exit 2; }
  [[ -z "$TEMPLATE" || -z "$LANG_ARG" ]] || { echo "--template and --lang are mutually exclusive" >&2; exit 2; }
fi
spacetime init --non-interactive --project-name "$PROJECT_NAME" ${TEMPLATE:+--template "$TEMPLATE"} ${LANG_ARG:+--lang "$LANG_ARG"}

Try / catch

#!/usr/bin/env bash
if ! spacetime init --non-interactive --project-name "$PROJECT_NAME" 2>err.log; then
  if grep -q "must be provided in non-interactive mode" err.log; then
    echo "CI misconfig: missing --template/--lang for non-interactive init" >&2
    exit 2
  fi
  cat err.log >&2; exit 1
fi

Prevention

When it happens

Trigger: `spacetime init --non-interactive --project-name my-app` with no `--template` and no `--lang`; CI jobs or Docker builds that assumed interactive defaults; piping stdin to init.

Common situations: Automated pipelines written by recording an interactive session; forgetting that non-interactive mode trades prompts for required flags.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/a16914914707d96b. Report an issue: GitHub.