grafana/k6 · error
the built-in check() does not support async functions as arg
Error message
the built-in check() does not support async functions as arguments. Use the JavaScript utils library as a replacement. Refer to https://grafana.com/docs/k6/latest/javascript-api/jslib/utils/check/ for more info
What it means
While iterating the checks object, k6 rejects values that are async functions (internal/js/modules/k6/k6.go:180). Check callbacks must return their boolean synchronously so the check metric can be tagged and emitted immediately; an async callback returns a promise whose result would arrive after the metric was recorded. The error message directs you to the jslib/k6 utils check replacement, which supports async check functions.
Source
Thrown at internal/js/modules/k6/k6.go:182
}
}
succ := true
var exc error
obj := checks.ToObject(rt)
for _, name := range obj.Keys() {
if strings.Contains(name, lib.GroupSeparator) {
return false, lib.ErrNameContainsGroupSeparator
}
val := obj.Get(name)
tags := commonTagsAndMeta.Tags
if state.Options.SystemTags.Has(metrics.TagCheck) {
tags = tags.With("check", name)
}
if common.IsAsyncFunction(rt, val) {
return false, errors.New("the built-in check() does not support async functions as arguments. " +
"Use the JavaScript utils library as a replacement. " +
"Refer to https://grafana.com/docs/k6/latest/javascript-api/jslib/utils/check/ for more info")
}
// Resolve callables into values.
fn, ok := sobek.AssertFunction(val)
if ok {
tmpVal, err := fn(sobek.Undefined(), arg0)
val = tmpVal
if err != nil {
val = rt.ToValue(false)
exc = err
}
}
booleanVal := val.ToBoolean()
if !booleanVal {
// A single failure makes the return value false.
succ = falseView on GitHub (pinned to 93accf6570)
Solutions
- Use jslib.k6.io's utils check: `import check from 'https://jslib.k6.io/k6-utils/1.5.0/check'` which supports async check functions
- Make the check callback synchronous: perform awaits before check() and assert on the resolved value
- Move async assertions out of check and record results with a custom metric or k6.check on precomputed booleans
Example fix
// before
check(res, { 'payload ok': async (r) => (await r.json()).code === 0 });
// after
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/check';
check(res, { 'payload ok': async (r) => (await r.json()).code === 0 }); Defensive patterns
Strategy: type-guard
Validate before calling
const AsyncFunction = (async () => {}).constructor;
const hasAsyncCheck = Object.values(checks).some((v) => v instanceof AsyncFunction);
if (hasAsyncCheck) { throw new TypeError('use jslib/k6-utils check for async check functions'); } Type guard
const containsAsyncCheck = (checks) =>
Object.values(checks).some((v) => v instanceof (async () => {}).constructor); Try / catch
try {
check(res, checks);
} catch (e) {
if (String(e.message).includes('does not support async functions')) {
throw new Error('replace k6/check with https://jslib.k6.io/k6-utils check for async assertions');
}
throw e;
} Prevention
- Import check from jslib.k6.io k6-utils when any assertion is async
- Await async data before check() and assert synchronously on the resolved values
- Keep check bodies one-line boolean expressions over precomputed values
When it happens
Trigger: `check(res, { 'ok': async (r) => { ... return r.status === 200 } })` — any check value defined as an async function or async arrow.
Common situations: Migrating from Playwright/Puppeteer-style scripts where async predicates are normal; wrapping checks around async helper calls; refactoring http_async or browser-based scripts into check bodies.
Related errors
- group() does not support async functions as arguments, pleas
- Uncaught (in promise) ${value}
- predicate function is not callable
- empty gRPC client
- not a gRPC client
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/bbc8126d0a54de95.
Report an issue: GitHub.