grafana/k6 · error

error while parsing use directives in

Error message

error while parsing use directives in %q: %w

What it means

Wrapped error from processUseDirectives: applying a 'use k6 ...' dependency constraint to the collected dependencies map failed — e.g. conflicting or unsatisfiable version constraints across directives and the dependencies manifest for the same dependency.

Solutions

  1. Inspect the wrapped error for which dependency/constraint conflicts
  2. Make 'use k6' directives and the manifest constraints consistent
  3. Remove duplicate or contradictory version constraints for the same dependency
Defensive patterns

Strategy: validation

When it happens

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

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at internal/cmd/launcher.go:411

		directive = strings.TrimSpace(strings.TrimPrefix(directive, "use k6"))
		dep := "k6"
		constraint := directive
		if strings.HasPrefix(directive, "with k6/x/") {
			directive = strings.TrimSpace(strings.TrimPrefix(directive, "with "))
			dep, constraint, _ = strings.Cut(directive, " ")
		}
		var con *semver.Constraints
		var err error
		if len(constraint) > 0 {
			con, err = semver.NewConstraint(constraint)
			if err != nil {
				return fmt.Errorf("error while parsing use directives constraint %q for %q in %q: %w", constraint, dep, name, err)
			}
		}

		err = deps.update(dep, con)
		if err != nil {
			return fmt.Errorf("error while parsing use directives in %q: %w", name, err)
		}
	}

	return nil
}

func findDirectives(text []byte) []string {
	// parse #! at beginning of file
	if bytes.HasPrefix(text, []byte("#!")) {
		_, text, _ = bytes.Cut(text, []byte("\n"))
	}

	var result []string

	for i := 0; i < len(text); {
		r, width := utf8.DecodeRune(text[i:])
		switch {
		case unicode.IsSpace(r) || r == rune(';'): // skip all spaces and ;

View on GitHub (pinned to 8d06114777)