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 = false

View on GitHub (pinned to 93accf6570)

Solutions

  1. 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
  2. Make the check callback synchronous: perform awaits before check() and assert on the resolved value
  3. 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

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


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