{"record":{"id":"606ef3d16f1f21f2","repo":"grafana/k6","slug":"default-stack-configured-but-the-default-project-i","errorCode":null,"errorMessage":"default stack configured but the default project ID is not available - please run `k6 cloud login` to refresh your configuration","messagePattern":"default stack configured but the default project ID is not available - please run `k6 cloud login` to refresh your configuration","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud.go","lineNumber":555,"sourceCode":"\nfunc resolveDefaultProjectID(\n\tgs *state.GlobalState,\n\tcloudConfig *cloudapi.Config,\n) (int64, error) {\n\t// Priority: projectID -> default stack from config\n\tif cloudConfig.ProjectID.Valid && cloudConfig.ProjectID.Int64 > 0 {\n\t\treturn cloudConfig.ProjectID.Int64, nil\n\t}\n\tif cloudConfig.StackID.Valid && cloudConfig.StackID.Int64 != 0 {\n\t\tif cloudConfig.DefaultProjectID.Valid && cloudConfig.DefaultProjectID.Int64 > 0 {\n\t\t\tstackName := cloudConfig.StackURL.String\n\t\t\tif !cloudConfig.StackURL.Valid {\n\t\t\t\tstackName = fmt.Sprintf(\"stack-%d\", cloudConfig.StackID.Int64)\n\t\t\t}\n\t\t\tgs.Logger.Warnf(\"No projectID specified, using default project of the %s stack\\n\", stackName)\n\t\t\treturn cloudConfig.DefaultProjectID.Int64, nil\n\t\t}\n\t\treturn 0, fmt.Errorf(\n\t\t\t\"default stack configured but the default project ID is not available - \" +\n\t\t\t\t\"please run `k6 cloud login` to refresh your configuration\")\n\t}\n\n\t// Return 0 to let the backend pick the project (old behavior)\n\treturn 0, nil\n}\n\nfunc resolveAndSetProjectID(\n\tgs *state.GlobalState,\n\tcloudConfig *cloudapi.Config,\n\ttmpCloudConfig map[string]any,\n\tarc *lib.Archive,\n) error {\n\tprojectID, err := resolveDefaultProjectID(gs, cloudConfig)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/cloud.go#L537-L573","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run `k6 cloud login` again to refresh stack ID and default project together","Or pass --project-id / set K6_CLOUD_PROJECT_ID to name the project explicitly","If it persists after re-login, verify the account actually has a project in that stack"],"exampleFix":"# before\nk6 cloud script.js  # stale config, no default project\n# after\nk6 cloud login\nk6 cloud script.js\n# or: k6 cloud --project-id 123 script.js","handlingStrategy":"validation","validationCode":"// pre-flight after login: ensure a project is resolvable\nout, err := exec.Command(\"k6\", \"config\", \"show\").Output() // or parse config.json\nif err == nil && !strings.Contains(string(out), \"default_project_id\") {\n    // pass --project-id explicitly on every cloud run\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `k6 cloud login` immediately after upgrading k6 or changing stacks","Pin --project-id / K6_CLOUD_PROJECT_ID in CI so runs never depend on stored defaults","Treat 'stack set but no default project' as a stale-config signal and refresh credentials"],"tags":["configuration","cloud","auth","project-id"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}