tauri-apps/tauri · error

Failed to render template

Error message

Failed to render template

What it means

The Tauri CLI scaffolds projects by rendering embedded Handlebars templates file-by-file via render_with_generator (used by `tauri init` and `tauri android/ios init`). This panic fires when handlebars.render_template_to_write returns an Err: the template file has invalid Handlebars syntax (unbalanced block expressions, bad partials) or writing the rendered output fails. The CLI treats its template scaffolding as infallible, so any render error aborts the process.

Source

Thrown at crates/tauri-cli/src/helpers/template.rs:85

  out_file_generator: &mut F,
) -> crate::Result<()> {
  let out_dir = out_dir.as_ref();
  for file in dir.files() {
    let mut file_path = file.path().to_path_buf();
    // cargo for some reason ignores the /templates folder packaging when it has a Cargo.toml file inside
    // so we rename the extension to `.crate-manifest`
    if let Some(extension) = file_path.extension() {
      if extension == "crate-manifest" {
        file_path.set_extension("toml");
      }
    }
    if let Some(mut output_file) = out_file_generator(file_path.clone())
      .fs_context("failed to generate output file", file_path.clone())?
    {
      if let Some(utf8) = file.contents_utf8() {
        handlebars
          .render_template_to_write(utf8, &data, &mut output_file)
          .expect("Failed to render template");
      } else {
        output_file
          .write_all(file.contents())
          .fs_context("failed to write template", file_path.clone())?;
      }
    }
  }
  for dir in dir.dirs() {
    render_with_generator(handlebars, data, dir, out_dir, out_file_generator)?;
  }
  Ok(())
}

View on GitHub (pinned to 52e4b6e71d)

Solutions

  1. Re-run the command in a clean, writable project directory and confirm the target directory is writable and the disk is not full.
  2. If you maintain custom templates, validate their Handlebars syntax by rendering each file standalone with the handlebars crate before shipping.
  3. Reinstall the CLI (npm/yarn/pnpm/cargo install tauri-cli) in case the install is corrupted.
  4. Upgrade @tauri-apps-cli / tauri-cli to the latest version; template regressions are fixed in patches.
  5. If it reproduces on the latest version, open an issue with the CLI version and the exact command.
Defensive patterns

Strategy: validation

Validate before calling

// For CLI forks bundling custom Handlebars templates:
use handlebars::Handlebars;

fn assert_templates_render(registry: &Handlebars, files: &[&str]) {
    for f in files {
        let src = std::fs::read_to_string(f).expect("read template");
        // compile-only pass: panics with a precise error instead of inside tauri init
        registry.register_template_string(f, src).expect("template syntax error");
    }
}

Try / catch

// These are Rust panics (expect), not Result errors: when driving the CLI
// programmatically, run it as a subprocess and treat non-zero exit + stderr
// match on the panic message as the catch path.
let out = std::process::Command::new("tauri").args(["init"]).output()?;
if !out.status.success() && String::from_utf8_lossy(&out.stderr).contains("Failed to render template") {
    // handle scaffolding failure: clean partial output, retry, or report
}

Prevention

When it happens

Trigger: Running `tauri init` or `tauri android init` / `tauri ios init` where a template asset contains malformed Handlebars, or where the destination output file cannot be written (read-only directory, disk full). Files whose contents are not valid UTF-8 are copied verbatim and do not hit this path.

Common situations: Forked/modified CLI builds with edited embedded templates; scaffolding into a directory the user cannot write to; a CLI release with a template regression; corrupted npm install of @tauri-apps/cli.

Related errors


AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20). Data as JSON: /api/errors/2e5fbedad6a1a3a9. Report an issue: GitHub.