grafana/k6 · error

default stack configured but the default project ID is not a

Error message

default stack configured but the default project ID is not available - please run `k6 cloud login` to refresh your configuration

What it means

While resolving the project for a cloud run, k6 found a stack ID but no usable default project ID (DefaultProjectID unset or <= 0). The stack ID and default project are both written by `k6 cloud login`; the config on disk is therefore incomplete or stale. k6 refuses to guess and asks you to refresh the login or name a project explicitly.

Source

Thrown at internal/cmd/cloud.go:555

func resolveDefaultProjectID(
	gs *state.GlobalState,
	cloudConfig *cloudapi.Config,
) (int64, error) {
	// Priority: projectID -> default stack from config
	if cloudConfig.ProjectID.Valid && cloudConfig.ProjectID.Int64 > 0 {
		return cloudConfig.ProjectID.Int64, nil
	}
	if cloudConfig.StackID.Valid && cloudConfig.StackID.Int64 != 0 {
		if cloudConfig.DefaultProjectID.Valid && cloudConfig.DefaultProjectID.Int64 > 0 {
			stackName := cloudConfig.StackURL.String
			if !cloudConfig.StackURL.Valid {
				stackName = fmt.Sprintf("stack-%d", cloudConfig.StackID.Int64)
			}
			gs.Logger.Warnf("No projectID specified, using default project of the %s stack\n", stackName)
			return cloudConfig.DefaultProjectID.Int64, nil
		}
		return 0, fmt.Errorf(
			"default stack configured but the default project ID is not available - " +
				"please run `k6 cloud login` to refresh your configuration")
	}

	// Return 0 to let the backend pick the project (old behavior)
	return 0, nil
}

func resolveAndSetProjectID(
	gs *state.GlobalState,
	cloudConfig *cloudapi.Config,
	tmpCloudConfig map[string]any,
	arc *lib.Archive,
) error {
	projectID, err := resolveDefaultProjectID(gs, cloudConfig)
	if err != nil {
		return err
	}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Run `k6 cloud login` again to refresh stack ID and default project together
  2. Or pass --project-id / set K6_CLOUD_PROJECT_ID to name the project explicitly
  3. If it persists after re-login, verify the account actually has a project in that stack

Example fix

# before
k6 cloud script.js  # stale config, no default project
# after
k6 cloud login
k6 cloud script.js
# or: k6 cloud --project-id 123 script.js
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight after login: ensure a project is resolvable
out, err := exec.Command("k6", "config", "show").Output() // or parse config.json
if err == nil && !strings.Contains(string(out), "default_project_id") {
    // pass --project-id explicitly on every cloud run
}

Prevention

When it happens

Trigger: resolveProjectID reaches the branch where StackID is set, --project-id/K6_CLOUD_PROJECT_ID are absent, and the stored DefaultProjectID is missing or non-positive — typically after upgrading k6 with a config written by an older version, or after a login against a stack that returned no default project.

Common situations: k6 upgraded in place keeping an old config.json; token+stack set manually via env vars without ever running login; the login API response changed or returned no default project for that stack.

Related errors


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