grafana/k6 · error
could not load and configure the test: %w
Error message
could not load and configure the test: %w
What it means
In the --local-execution path of `k6 cloud run`, the test is loaded and configured by loadAndConfigureLocalTest (using getCloudRunLocalExecutionConfig); any failure is wrapped with this message. The wrapped cause is the ordinary test-loading pipeline, so it ranges from file and syntax errors to invalid options, bad env-var config, or a missing default export.
Source
Thrown at internal/cmd/cloud_run.go:153
)
}
if c.noCloudLogs {
return errext.WithExitCodeIfNone(
fmt.Errorf("the --no-cloud-logs flag can only be used in conjunction with the --local-execution flag"),
exitcodes.InvalidConfig,
)
}
return c.deprecatedCloudCmd.preRun(cmd, args)
}
func (c *cmdCloudRun) run(cmd *cobra.Command, args []string) error {
if c.localExecution {
c.runCmd.loadConfiguredTest = func(*cobra.Command, []string) (*loadedAndConfiguredTest, execution.Controller, error) {
test, err := loadAndConfigureLocalTest(c.runCmd.gs, cmd, args, getCloudRunLocalExecutionConfig)
if err != nil {
return nil, nil, fmt.Errorf("could not load and configure the test: %w", err)
}
if err := createCloudTest(c.runCmd.gs, test); err != nil {
if errors.Is(err, errCloudAuth) {
return nil, nil, err
}
return nil, nil, fmt.Errorf("could not create the cloud test run: %w", err)
}
return test, local.NewController(), nil
}
return c.runCmd.run(cmd, args)
}
// When running the `k6 cloud run` command explicitly disable the usage report.
c.noUsageReport = true
return c.deprecatedCloudCmd.run(cmd, args)View on GitHub (pinned to 93accf6570)
Solutions
- Run `k6 run script.js` (or `k6 inspect script.js`) locally to surface the exact underlying error
- Fix the reported script issue: path, syntax, imports, missing default export
- Validate options and any --config file / K6_* env overrides named in the wrapped error
Example fix
// before: script.js exports nothing
const http = require('k6/http')
// after
const http = require('k6/http')
export default function () { http.get('https://test.k6.io') } Defensive patterns
Strategy: validation
Validate before calling
// pre-flight: the script must at least load
if err := exec.Command("k6", "inspect", "script.js").Run(); err != nil {
log.Fatalf("script.js does not load: %v", err)
}
// then: k6 cloud run --local-execution script.js Try / catch
test, err := loadAndConfigureLocalTest(gs, cmd, args, getCloudRunLocalExecutionConfig)
if err != nil {
return fmt.Errorf("could not load and configure the test: %w", err)
// unwrap with errors.Unwrap in callers to distinguish file vs options vs env errors
} Prevention
- Run `k6 inspect script.js` (or `k6 run`) in CI before the cloud step to catch load errors cheaply
- Keep scripts self-contained: valid imports, a default export, and no machine-specific paths
- Validate --config files and K6_* env overrides in a lint step for the pipeline
When it happens
Trigger: Running `k6 cloud run --local-execution script.js` where the file does not exist, contains a JavaScript syntax or import error, exports no default function, has invalid options (scenarios, thresholds), or where a K6_* env var / --config file fails validation.
Common situations: Path typos or wrong working directory in CI; a script that runs under `k6 run` on an older k6 but uses options the newer cloud-run config rejects; env vars like K6_CLOUD_TIMEOUT set to non-durations; broken imports after dependency changes.
Related errors
- metrics push URL is required
- no secret sources are configured
- Unexpected end of selector while parsing selector `${selecto
- Error while parsing selector `${selector}`: ${e.message}
- Error while parsing selector `${selector}` - cannot use ${op
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/3db6b9e78252cbbf.
Report an issue: GitHub.