grafana/k6 · error

invalid template type

Error message

invalid template type %q

What it means

GetTemplate's fallback error: the argument matched neither a built-in template type nor a readable template file, and no file with that name exists in the current directory (the variant with 'did you mean ./%s?' fires when such a local file exists). Pure input validation on the template name passed to 'k6 new'.

Solutions

  1. Use a built-in template type supported by 'k6 new' (e.g. default, browser-module, grpc-module)
  2. Or pass a path to an existing custom template file
  3. If the file is in the current directory, prefix it with ./ (e.g. k6 new --template ./my.js)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/cmd/templates/templates.go:104 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/bb460a218a6d3991. Report an issue: GitHub.

Appendix: 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 01ffac6f24)