grafana/k6 · error
no exported functions in script
Error message
no exported functions in script
What it means
After the export scan, the bundle found zero callable exports (b.callableExports is empty). k6 executes at least one exported function per iteration — normally the default function — so a script with no exported functions has nothing to run.
Source
Thrown at internal/js/bundle.go:238
b.preInitState.Logger.WithError(err).Warn("There were unknown fields in the options exported in the script")
err = nil
}
case consts.SetupFn:
err = errors.New("exported 'setup' must be a function")
return
case consts.TeardownFn:
err = errors.New("exported 'teardown' must be a function")
return
}
}
})
<-ch
if err != nil {
return err
}
if len(b.callableExports) == 0 {
return errors.New("no exported functions in script")
}
return nil
}
func beautifyOptionsJSONUnmarshalError(data []byte, err error) error {
unmarshalTypError := new(json.UnmarshalTypeError)
if errors.As(err, &unmarshalTypError) {
e := unmarshalTypError
previousNewLineIndex := max(bytes.LastIndexByte(data[:e.Offset], '\n'), 0)
nextNewLineIndex := max(min(bytes.IndexByte(data[e.Offset:], '\n'), len(data)-1), (int)(e.Offset))
info := strings.TrimSpace(string(data[previousNewLineIndex:nextNewLineIndex]))
err = fmt.Errorf("parsing options from script got error while parsing %q: %w", info, e)
}
return err
}
View on GitHub (pinned to 93accf6570)
Solutions
- Add a default function: `export default function () { /* test logic */ }`
- If the file is really a helper module, point `k6 run` at the actual entry script instead
- For scenarios-only configs, still export an (empty) default function so iterations exist
Example fix
// before
export const options = { vus: 1, duration: '10s' };
// after
export const options = { vus: 1, duration: '10s' };
export default function () { http.get('https://test.k6.io'); } Defensive patterns
Strategy: validation
Validate before calling
// entry-script guard: fail loudly if nothing is runnable
let hasDefault = false;
try { hasDefault = typeof module_default === 'function'; } catch (_) {}
// simpler: ensure the file literally contains 'export default function' before shipping
curl -s script.js | grep -q 'export default function' || echo 'WARN: no default export' >&2 Prevention
- Every entry script must `export default function` — even an empty one
- Keep helper modules in a separate directory from entry scripts to avoid running them directly
- Add a CI check that greps the entry file for a default export before `k6 run`
When it happens
Trigger: A script exporting only `options` (or other constants) with no `export default function`; helper/util modules mistakenly passed to `k6 run` as the entry script.
Common situations: Options-only snippets saved as a script; refactors that wrapped the default function in a const without exporting it; running a shared library file directly.
Related errors
- exported 'setup' must be a function
- exported 'teardown' must be a function
- open() can't be used with an empty filename
- predicate function is not callable
- only arrays can be made into SharedArray
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/68ca62cb445740cd.
Report an issue: GitHub.