grafana/k6 · error
invalid template type %q
Error message
invalid template type %q
What it means
The --template value matched no built-in template type, contains no path separator, and no file with that name exists in the current directory, so k6 reports "invalid template type \"<tpl>\"". Built-in types are selected by name (MinimalTemplate, ProtocolTemplate, BrowserTemplate); anything else must be a file path containing a separator.
Source
Thrown at internal/cmd/templates/templates.go:104
if err != nil {
return nil, fmt.Errorf("failed to read template file %s: %w", tpl, err)
}
tmpl, err := template.New(filepath.Base(tplPath)).Parse(string(content))
if err != nil {
return nil, fmt.Errorf("failed to parse template file %s: %w", tpl, err)
}
return tmpl, nil
}
// Check if there's a file with this name in current directory
exists, err := fsext.Exists(tm.fs, fsext.JoinFilePath(".", tpl))
if err == nil && exists {
return nil, fmt.Errorf("invalid template type %q, did you mean ./%s?", tpl, tpl)
}
return nil, fmt.Errorf("invalid template type %q", tpl)
}
// isFilePath checks if the given string looks like a file path by detecting path separators
// We assume that built-in template names don't contain path separators
func isFilePath(path string) bool {
return strings.ContainsRune(path, filepath.Separator) || strings.ContainsRune(path, '/')
}
// TemplateArgs represents arguments passed to templates
type TemplateArgs struct {
ScriptName string
ProjectID string
}
// ExecuteTemplate applies the template with provided arguments and writes to the provided writer
func ExecuteTemplate(w io.Writer, tmpl *template.Template, args TemplateArgs) error {
return tmpl.Execute(w, args)
}View on GitHub (pinned to 93accf6570)
Solutions
- Use one of the built-in names supported by your build: minimal, protocol, browser (check 'k6 new --help')
- Pass an existing template file via ./relative or an absolute path
- Upgrade k6 if documentation references a template your version lacks
Example fix
# before k6 new --template=browsr script.js # after k6 new --template=browser script.js
Defensive patterns
Strategy: validation
Validate before calling
# Allow-list built-in names; anything else must be an existing file
case "$tpl" in
minimal|protocol|browser) ;;
*) [ -f "$tpl" ] || { echo "unknown template: $tpl" >&2; exit 2; } ;;
esac
k6 new --template="$tpl" script.js Prevention
- Check 'k6 new --help' for the template names your build supports
- Double-check spelling of built-in template names
- Upgrade k6 when docs reference templates your binary lacks
When it happens
Trigger: Typos such as --template=minimal-new or --template=browsr; passing a bare filename that does not exist in the cwd; using a template name that exists only in a different k6 version.
Common situations: Version differences where a template name exists in newer k6 but not the installed one; outdated blog posts or docs listing template names; copy-paste errors.
Related errors
- error retrieving template: %w
- 104
- invalid tag, empty name
- invalid tag, empty value
- accepts %d arg(s), received %d: %s
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/bb460a218a6d3991.
Report an issue: GitHub.