{"record":{"id":"9b6ace89f8f12bc8","repo":"grafana/k6","slug":"somehow-a-commonjs-module-is-not-wrapped-in-a-func","errorCode":null,"errorMessage":"Somehow a CommonJS module is not wrapped in a function - this is a k6 bug, please report it (https://github.com/grafana/k6/issues)","messagePattern":"Somehow a CommonJS module is not wrapped in a function - this is a k6 bug, please report it \\(https://github\\.com/grafana/k6/issues\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"js/modules/cjsmodule.go","lineNumber":74,"sourceCode":"\nfunc (cmi *cjsModuleInstance) HasTLA() bool { return false }\n\nfunc (cmi *cjsModuleInstance) RequestedModules() []string { return cmi.w.RequestedModules() }\n\nfunc (cmi *cjsModuleInstance) ExecuteModule(\n\trt *sobek.Runtime, _, _ func(any) error,\n) (sobek.CyclicModuleInstance, error) {\n\tv, err := rt.RunProgram(cmi.w.prg)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tmodule := rt.NewObject()\n\tcmi.exports = rt.NewObject()\n\t_ = module.Set(\"exports\", cmi.exports)\n\tcall, ok := sobek.AssertFunction(v)\n\tif !ok {\n\t\tpanic(\"Somehow a CommonJS module is not wrapped in a function - \" +\n\t\t\t\"this is a k6 bug, please report it (https://github.com/grafana/k6/issues)\")\n\t}\n\tif _, err = call(cmi.exports, module, cmi.exports); err != nil {\n\t\treturn nil, err\n\t}\n\n\texportsV := module.Get(\"exports\")\n\tif sobek.IsNull(exportsV) {\n\t\treturn nil, errors.New(\"CommonJS's exports must not be null\")\n\t}\n\tcmi.exports = exportsV.ToObject(rt)\n\n\t// this will be called multiple times we only need to update this on the first VU\n\tif cmi.w.exportedNames == nil {\n\t\tcmi.w.exportedNames = cmi.exports.Keys()\n\t\tif cmi.w.exportedNames == nil { // workaround if a CommonJS module does not have exports\n\t\t\tcmi.w.exportedNames = make([]string, 0)\n\t\t}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/js/modules/cjsmodule.go#L56-L92","documentation":"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.","triggerScenarios":"Thrown at js/modules/cjsmodule.go:74 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}