grafana/k6 · error

invalid dependencies manifest %w

Error message

invalid dependencies manifest %w

What it means

Thrown by parseManifest when the dependency manifest string (typically the K6_DEPENDENCIES environment variable or the manifest captured from a built archive) is non-empty but is not a valid JSON object of dependency-name -> constraint-string pairs. json.Unmarshal fails on any JSON syntax error (truncated value, array instead of object, quotes issues) and the error is wrapped with this message. Note: a constraint string inside a syntactically valid JSON object that semver rejects fails later in dependenciesFromMap and is NOT covered by this wrap.

Source

Thrown at internal/cmd/launcher.go:465

			if idx < 0 {
				return result
			}
			i += width + idx + 2
		default:
			return result
		}
	}
	return result
}

func parseManifest(manifestString string) (dependencies, error) {
	if manifestString == "" {
		return nil, nil //nolint:nilnil
	}

	manifestMap := make(map[string]string)
	if err := json.Unmarshal([]byte(manifestString), &manifestMap); err != nil {
		return nil, fmt.Errorf("invalid dependencies manifest %w", err)
	}
	return dependenciesFromMap(manifestMap)
}

// completionTimeout bounds the cache lookup for shell completion requests.
// The build service is reachable but not guaranteed responsive; without a
// deadline a stall would hang the shell on every TAB.
const completionTimeout = 3 * time.Second

// completeExtension handles a shell completion request for an unregistered
// extension subcommand. If the matching provisioned binary is already cached
// locally, it delegates the completion request to that binary. Otherwise it
// returns nil (no completions) so the shell does not hang waiting on a build.
func completeExtension(gs *state.GlobalState, extName string, prov provisioner) error {
	deps, err := dependenciesFromSubcommand(gs, extName)
	if err != nil {
		gs.Logger.WithError(err).Debug("Failed to build completion deps")
		return nil

View on GitHub (pinned to 93accf6570)

Solutions

  1. Echo the exact value: `echo "$K6_DEPENDENCIES"` and validate it as JSON: `echo "$K6_DEPENDENCIES" | jq .`
  2. Rewrite as a JSON object mapping dependency to semver constraint: K6_DEPENDENCIES='{"k6": ">=v0.56.0", "k6/x/sql": "0.x"}'
  3. Use double quotes for keys/values and single quotes around the whole env var in POSIX shells
  4. If the error appears when loading an archive, rebuild the archive (k6 archive script.js) instead of hand-editing its manifest

Example fix

# before
export K6_DEPENDENCIES='{"k6": ">=v0.56.0''
# error: invalid dependencies manifest ...

# after
export K6_DEPENDENCIES='{"k6": ">=v0.56.0"}'
Defensive patterns

Strategy: validation

Validate before calling

# Validate K6_DEPENDENCIES is a JSON object of dep->range before k6 reads it
node -e '
const m = process.env.K6_DEPENDENCIES; if (!m) process.exit(0);
const o = JSON.parse(m);
if (Array.isArray(o) || typeof o !== "object") process.exit(1);
' || { echo 'K6_DEPENDENCIES must be a JSON object'; exit 1; }

Type guard

function isDependenciesManifest(v) {
  if (typeof v !== "string" || v === "") return false;
  try { const o = JSON.parse(v); return !!o && typeof o === "object" && !Array.isArray(o); }
  catch { return false; }
}

Prevention

When it happens

Trigger: Setting K6_DEPENDENCIES='{"k6": ">=v0.50"' (missing closing brace), K6_DEPENDENCIES='k6>=v0.50' (not JSON), an array like '["k6"]', or single-quoted keys; also loading an archive whose embedded manifest was corrupted.

Common situations: CI pipelines composing K6_DEPENDENCIES by string concatenation and forgetting a brace; shell quoting that strips inner double quotes; scripts that write the env var from YAML where quotes were normalized to single quotes.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/cdd71f156ad544c5. Report an issue: GitHub.