grafana/k6 · error
Somehow a CommonJS module is not wrapped in a function - thi
Error message
Somehow a CommonJS module is not wrapped in a function - this is a k6 bug, please report it (https://github.com/grafana/k6/issues)
What it means
Error "Somehow a CommonJS module is not wrapped in a function - this is a k6 bug, please report it (https://github.com/grafana/k6/issues)" thrown in grafana/k6.
Source
Thrown at js/modules/cjsmodule.go:74
func (cmi *cjsModuleInstance) HasTLA() bool { return false }
func (cmi *cjsModuleInstance) RequestedModules() []string { return cmi.w.RequestedModules() }
func (cmi *cjsModuleInstance) ExecuteModule(
rt *sobek.Runtime, _, _ func(any) error,
) (sobek.CyclicModuleInstance, error) {
v, err := rt.RunProgram(cmi.w.prg)
if err != nil {
return nil, err
}
module := rt.NewObject()
cmi.exports = rt.NewObject()
_ = module.Set("exports", cmi.exports)
call, ok := sobek.AssertFunction(v)
if !ok {
panic("Somehow a CommonJS module is not wrapped in a function - " +
"this is a k6 bug, please report it (https://github.com/grafana/k6/issues)")
}
if _, err = call(cmi.exports, module, cmi.exports); err != nil {
return nil, err
}
exportsV := module.Get("exports")
if sobek.IsNull(exportsV) {
return nil, errors.New("CommonJS's exports must not be null")
}
cmi.exports = exportsV.ToObject(rt)
// this will be called multiple times we only need to update this on the first VU
if cmi.w.exportedNames == nil {
cmi.w.exportedNames = cmi.exports.Keys()
if cmi.w.exportedNames == nil { // workaround if a CommonJS module does not have exports
cmi.w.exportedNames = make([]string, 0)
}View on GitHub (pinned to 93accf6570)
When it happens
Trigger: Thrown at js/modules/cjsmodule.go:74 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/9b6ace89f8f12bc8.
Report an issue: GitHub.