{"record":{"id":"68ca62cb445740cd","repo":"grafana/k6","slug":"no-exported-functions-in-script","errorCode":null,"errorMessage":"no exported functions in script","messagePattern":"no exported functions in script","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/bundle.go","lineNumber":238,"sourceCode":"\t\t\t\t\tb.preInitState.Logger.WithError(err).Warn(\"There were unknown fields in the options exported in the script\")\n\t\t\t\t\terr = nil\n\t\t\t\t}\n\t\t\tcase consts.SetupFn:\n\t\t\t\terr = errors.New(\"exported 'setup' must be a function\")\n\t\t\t\treturn\n\t\t\tcase consts.TeardownFn:\n\t\t\t\terr = errors.New(\"exported 'teardown' must be a function\")\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t})\n\t<-ch\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif len(b.callableExports) == 0 {\n\t\treturn errors.New(\"no exported functions in script\")\n\t}\n\n\treturn nil\n}\n\nfunc beautifyOptionsJSONUnmarshalError(data []byte, err error) error {\n\tunmarshalTypError := new(json.UnmarshalTypeError)\n\tif errors.As(err, &unmarshalTypError) {\n\t\te := unmarshalTypError\n\t\tpreviousNewLineIndex := max(bytes.LastIndexByte(data[:e.Offset], '\\n'), 0)\n\t\tnextNewLineIndex := max(min(bytes.IndexByte(data[e.Offset:], '\\n'), len(data)-1), int(e.Offset))\n\n\t\tinfo := strings.TrimSpace(string(data[previousNewLineIndex:nextNewLineIndex]))\n\t\terr = fmt.Errorf(\"parsing options from script got error while parsing %q: %w\", info, e)\n\t}\n\treturn err\n}\n","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/bundle.go#L220-L256","documentation":"After validating exports, populateExports (internal/js/bundle.go:238) requires at least one callable export (default, handle, setup, teardown, or scenario exec functions). A script that exports only data/objects has nothing for k6 to execute per-iteration, so the bundle is rejected with 'no exported functions in script'.","triggerScenarios":"A script whose only export is `export const options = {...}`; scripts that define functions but forget `export`; using `module.exports` in an ES module (or vice versa) so exports don't register; importing everything but exporting nothing.","commonSituations":"Options-only config files passed to `k6 run`; refactoring where `export default function () {...}` was moved into a helper file; module-format mismatches (ESM vs CommonJS under different compatibility modes).","solutions":["Add an entry point: `export default function () { ... }`.","Or define scenario exec functions and reference them in options.scenarios.","Verify the module format matches the file (ESM `export` vs CJS `module.exports`) and that the file has the right extension for the compatibility mode."],"exampleFix":"// before\nexport const options = { vus: 1, duration: '10s' };\n// after\nexport const options = { vus: 1, duration: '10s' };\nexport default function () { http.get('https://test.k6.io'); }","handlingStrategy":"validation","validationCode":"# quick pre-run sanity check in CI\nif ! grep -qE 'export\\s+(default\\s+)?(async\\s+)?function|export\\s+\\{[^}]*\\b(handle|setup|teardown)\\b' script.js; then\n  echo 'script has no exported functions for k6 to execute'; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Every k6 script template should start with export default function ().","Run `k6 inspect script.js` in CI — it fails fast on scripts with nothing callable."],"tags":["script-structure","exports","entrypoint","javascript"],"backgroundTag":"missing-entrypoint","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}