grafana/k6 · error

exported identifier %s must be a function

Error message

exported identifier %s must be a function

What it means

The script exports a `handleSummary` identifier, but its value is not callable (a number, string, object, etc.). k6 checks the export with AssertFunction after confirming it exists; anything that is not a function is rejected before the summary machinery runs. Omitting the export entirely is fine — only a non-function export triggers this.

Source

Thrown at internal/js/runner.go:486

		handleSummaryData = summaryData
	}

	return noColor, enableColors, newMachineReadableSummary, summaryCode, summaryData, handleSummaryData, err
}

func runUserProvidedHandleSummaryCallback(
	summaryCtx context.Context,
	vu *VU,
	handleSummaryData sobek.Value,
) (sobek.Value, error) {
	fn := vu.getExported(consts.HandleSummaryFn)
	if fn == nil {
		return sobek.Undefined(), nil
	}

	handleSummaryFn, ok := sobek.AssertFunction(fn)
	if !ok {
		return nil, fmt.Errorf("exported identifier %s must be a function", consts.HandleSummaryFn)
	}

	callbackResult, _, _, err := vu.runFn(summaryCtx, false, handleSummaryFn, nil, handleSummaryData)
	if err != nil {
		errText, fields := errext.Format(err)
		vu.Runner.preInitState.Logger.WithFields(fields).Error(errText)
	}

	// In case of error, we only want to log it
	// but still proceed with the built-in summary handler, so we return nil.
	return callbackResult, nil
}

func prepareHandleWrapperArgs(
	vu *VU,
	noColor, enableColors, newMachineReadableSummary bool,
	callbackResult, handleSummaryData, summaryData sobek.Value,
) []sobek.Value {

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Export handleSummary as a function: export function handleSummary(data) { ... }
  2. Remove the export if a default summary is wanted
  3. Do not assign constants or objects to handleSummary; the exported binding must be a callable
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at internal/js/runner.go:486 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/cea751f683722984. Report an issue: GitHub.