grafana/k6 · error

invalid template type

Error message

invalid template type %q, did you mean ./%s?

What it means

`k6 new -t NAME` first matches built-in names (minimal, protocol, browser). A value without path separators that is not built-in falls through: if a file with that name exists in the current directory, k6 assumes you meant to use it as a file template but forgot the ./ prefix, and emits this 'did you mean' hint. The sibling message without the hint fires when no such file exists.

Solutions

  1. Prefix the path so it is treated as a file: k6 new -t ./script.js new-script.js
  2. Or use a built-in template name: minimal, protocol, or browser

Example fix

# before
k6 new -t script.js new-script.js

# after
k6 new -t ./script.js new-script.js
Defensive patterns

Strategy: validation

Validate before calling

# decide template intent before invoking k6 new
BUILTINS="minimal protocol browser"
tpl="$1"
case " $BUILTINS " in
  *" $tpl "*) ;;                                              # built-in: use as-is
  *) case "$tpl" in */*|*\\*) ;;                              # has a separator: file path
       *) if [ -e "./$tpl" ]; then tpl="./$tpl"; else echo "invalid template type '$tpl'" >&2; exit 1; fi;;
     esac;;
esac
k6 new -t "$tpl" new-script.js

Prevention

When it happens

Trigger: k6 new -t script.js when ./script.js exists → this error suggesting ./script.js; k6 new -t minimal.js (a local file) instead of -t minimal or -t ./minimal.js.

Common situations: Trying to base a new script on an existing local file and omitting ./; habit from other CLIs where bare filenames resolve as files.

Related errors


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

Appendix: source

Thrown at internal/cmd/templates/templates.go:101

		// Read the template content using the provided filesystem
		content, err := fsext.ReadFile(tm.fs, tplPath)
		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

View on GitHub (pinned to 01ffac6f24)