grafana/k6 · error

must be a number

Error message

must be a number

What it means

exportInt (used by File.seek) requires the value's Go export type to be exactly int64 -- i.e. an integral JavaScript number. Strings like "10" (explicitly called out in the source comment), fractional numbers such as 10.5, and BigInts all fail this check and surface as "seek() failed; reason: the offset/whence argument must be a number".

Source

Thrown at internal/js/modules/k6/experimental/fs/module.go:352

	uint8ArrayConstructor := rt.Get("Uint8Array")
	if isUint8Array := o.Get("constructor").SameAs(uint8ArrayConstructor); !isUint8Array {
		return false
	}

	return true
}

func exportInt(v sobek.Value) (int64, error) {
	if common.IsNullish(v) {
		return 0, errors.New("cannot be null or undefined")
	}

	// We initially tried using `ExportTo` with a int64 value argument, however
	// this led to a string passed as argument not being an error.
	// Thus, we explicitly check that the value is a number, by comparing
	// its export type to the type of an int64.
	if v.ExportType().Kind() != reflect.Int64 {
		return 0, errors.New("must be a number")
	}

	return v.ToInteger(), nil
}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Coerce before calling: file.seek(Number(offset), SeekMode.Start)
  2. Round fractional values: file.seek(Math.round(pos), whence)
  3. Use SeekMode.Start/Current/End constants instead of strings for whence

Example fix

// before
await file.seek(offsetStr, 'Start');

// after
import { SeekMode } from 'k6/experimental/fs';
await file.seek(Number(offsetStr), SeekMode.Start);
Defensive patterns

Strategy: validation

Validate before calling

function isSeekArg(v) {
  return typeof v === 'number' && Number.isInteger(v);
}

if (!isSeekArg(offset) || !isSeekArg(whence)) throw new TypeError('seek arguments must be integers');
await file.seek(offset, whence);

Type guard

/** @param {unknown} v @returns {v is number} */
const isInt = (v) => typeof v === 'number' && Number.isInteger(v);

Prevention

When it happens

Trigger: file.seek('1024', 0) with a string offset read from CSV/stdin/config; file.seek(10.5, 0) with a fractional offset; passing whence as a string like 'Start' instead of the numeric SeekMode enum.

Common situations: Offsets parsed from external data files that stay strings; computed offsets from averages/percentages that are non-integral; using string mode names from other APIs.

Related errors


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