tauri-apps/tauri · error
Failed to setup custom handlebar template
Error message
Failed to setup custom handlebar template
What it means
When you configure a custom NSIS template, the bundler reads your template file and registers it with the handlebars registry. register_template_string fails if handlebars cannot parse the template (unclosed {{ }}, unknown block syntax, invalid partial), and this expect() panics with 'Failed to setup custom handlebar template'. It means your custom installer template is syntactically invalid as a handlebars template.
Source
Thrown at crates/tauri-bundler/src/bundle/windows/nsis/mod.rs:632
let mut output = String::new();
for c in s.chars() {
match c {
'\"' => output.push_str("$\\\""),
'$' => output.push_str("$$"),
'`' => output.push_str("$\\`"),
'\n' => output.push_str("$\\n"),
'\t' => output.push_str("$\\t"),
'\r' => output.push_str("$\\r"),
_ => output.push(c),
}
}
output
});
if let Some(path) = custom_template_path {
handlebars
.register_template_string("installer.nsi", std::fs::read_to_string(path)?)
.map_err(|e| e.to_string())
.expect("Failed to setup custom handlebar template");
} else {
handlebars
.register_template_string("installer.nsi", include_str!("./installer.nsi"))
.map_err(|e| e.to_string())
.expect("Failed to setup handlebar template");
}
write_utf8_with_bom(
output_path.join("FileAssociation.nsh"),
include_bytes!("./FileAssociation.nsh"),
)?;
write_utf8_with_bom(output_path.join("utils.nsh"), include_bytes!("./utils.nsh"))?;
let installer_nsi_path = output_path.join("installer.nsi");
write_utf8_with_bom(
&installer_nsi_path,
handlebars.render("installer.nsi", &data)?,
)?;View on GitHub (pinned to 52e4b6e71d)
Solutions
- Open your custom template and find the handlebars syntax error — run `npx handlebars <file>` or an editor with handlebars highlighting to locate unbalanced {{ }} blocks.
- Diff your custom template against the stock installer.nsi of the exact tauri-bundler version you use (crates/tauri-bundler/src/bundle/windows/nsis/installer.nsi) and re-apply your changes on top of the current stock template.
- Verify every {{#if}}/{{#each}} has a matching close tag and that variables you reference exist in the data object.
- Rebuild with `tauri build --bundles nsis`.
Example fix
; before — unclosed block in custom installer.nsi
{{#if installMode}}
!insertmacro REINSTALL_MODE
; after
{{#if installMode}}
!insertmacro REINSTALL_MODE
{{/if}} Defensive patterns
Strategy: validation
Validate before calling
// CI step: verify the custom NSIS template parses as handlebars before tauri build
// npx --yes handlebars-cli parse installer.nsi (non-zero exit = syntax error)
fn check_template_balance(src: &str) -> bool {
let mut depth = 0i32;
let mut rest = src;
while let Some(start) = rest.find("{{#") {
depth += 1;
rest = &rest[start + 3..];
}
depth >= 0
} Prevention
- Keep custom NSIS templates in version control and lint them in CI before release builds.
- After upgrading Tauri, re-diff your custom template against the new stock installer.nsi and port your changes.
- Ensure every {{#if}}/{{#each}} block has a matching {{/if}}/{{/each}}; test template edits locally with --bundles nsis before pushing.
When it happens
Trigger: `tauri build --bundles nsis` (Windows) with bundle > windows > nsis > installerHooks / custom template path pointing at a .nsi file containing malformed handlebars syntax — e.g. {{#if x}} without {{/if}}, a stray {{, or template comments that break parsing. The registration at crates/tauri-bundler/src/bundle/windows/nsis/mod.rs:632 maps the parse error to a string and immediately expects success.
Common situations: Editing the copied stock installer.nsi template and breaking a block; upgrading Tauri versions where the expected template variables/blocks changed while your old custom template keeps deprecated syntax; using NSIS `${...}` constructs adjacent to handlebars braces that confuse the parser.
Related errors
- failed to read resource folder name
- Failed to setup custom handlebar template
- Failed to setup handlebar template
- failed to read resource file name
- Failed to render template
AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20).
Data as JSON: /api/errors/a96a1843fc3568f1.
Report an issue: GitHub.