{"record":{"id":"2890dbca5f177344","repo":"grafana/k6","slug":"error-while-parsing-use-directives-constraint-q-f","errorCode":null,"errorMessage":"error while parsing use directives constraint %q for %q in %q: %w","messagePattern":"error while parsing use directives constraint %q for %q in %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/launcher.go","lineNumber":405,"sourceCode":"\tfor _, directive := range directives {\n\t\t// normalize spaces\n\t\tdirective = strings.ReplaceAll(directive, \"  \", \" \")\n\t\tif !strings.HasPrefix(directive, \"use k6\") {\n\t\t\tcontinue\n\t\t}\n\t\tdirective = strings.TrimSpace(strings.TrimPrefix(directive, \"use k6\"))\n\t\tdep := \"k6\"\n\t\tconstraint := directive\n\t\tif strings.HasPrefix(directive, \"with k6/x/\") {\n\t\t\tdirective = strings.TrimSpace(strings.TrimPrefix(directive, \"with \"))\n\t\t\tdep, constraint, _ = strings.Cut(directive, \" \")\n\t\t}\n\t\tvar con *semver.Constraints\n\t\tvar err error\n\t\tif len(constraint) > 0 {\n\t\t\tcon, err = semver.NewConstraint(constraint)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error while parsing use directives constraint %q for %q in %q: %w\", constraint, dep, name, err)\n\t\t\t}\n\t\t}\n\n\t\terr = deps.update(dep, con)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error while parsing use directives in %q: %w\", name, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc findDirectives(text []byte) []string {\n\t// parse #! at beginning of file\n\tif bytes.HasPrefix(text, []byte(\"#!\")) {\n\t\t_, text, _ = bytes.Cut(text, []byte(\"\\n\"))\n\t}\n","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/cmd/launcher.go#L387-L423","documentation":"Wrapped error from processUseDirectives while parsing a 'use k6 >=v0.50' (or 'use k6 with k6/x/ext constraint') directive in a script: the semver constraint string itself is invalid and could not be compiled by semver.NewConstraint.","triggerScenarios":"Thrown at internal/cmd/launcher.go:406 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use valid semver constraint syntax, e.g. '>= v0.50.0', '~0.53'","Check for typos in the version constraint after 'use k6' or 'with k6/x/...'"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}