{"record":{"id":"5f08fbfdceedd5c7","repo":"grafana/k6","slug":"the-module-q-was-not-previously-resolved-during-i","errorCode":null,"errorMessage":"the module %q was not previously resolved during initialization (__VU==0)","messagePattern":"the module %q was not previously resolved during initialization \\(__VU==0\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"js/modules/resolution.go","lineNumber":75,"sourceCode":"\t\tcompiler:  c,\n\t\treverse:   make(map[any]*url.URL),\n\t\tbase:      base,\n\t\tusage:     u,\n\t\tlogger:    logger,\n\t}\n}\n\nfunc (mr *ModuleResolver) resolveSpecifier(basePWD *url.URL, arg string) (*url.URL, error) {\n\tspecifier, err := loader.Resolve(basePWD, arg)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn specifier, nil\n}\n\nfunc (mr *ModuleResolver) initializeGoModule(name string) (sobek.ModuleRecord, error) {\n\tif mr.locked {\n\t\treturn nil, fmt.Errorf(notPreviouslyResolvedModule, name)\n\t}\n\tmod, ok := mr.goModules[name]\n\tif !ok {\n\t\tmr.unknownModules = append(mr.unknownModules, name)\n\t\treturn &unknownModule{name: name, requested: make(map[string]struct{})}, nil\n\t}\n\t// We would have hit the cache if this isn't the first time, so each distinct\n\t// module is recorded once. An extension is identified by membership in the\n\t// extension registry, not by its k6/x/ name: its resolved registry entry is\n\t// recorded under \"extensions\" so the report needs no re-resolution, while\n\t// built-in modules stay in the \"modules\" bucket.\n\tif e, ok := ext.Get(ext.JSExtension)[name]; ok {\n\t\tif err := mr.usage.Values(\"extensions\", e); err != nil {\n\t\t\tmr.logger.WithError(err).Warnf(\"Error while reporting usage of extension %q\", name)\n\t\t}\n\t} else if err := mr.usage.Strings(\"modules\", name); err != nil {\n\t\tmr.logger.WithError(err).Warnf(\"Error while reporting usage of module %q\", name)\n\t}","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/js/modules/resolution.go#L57-L93","documentation":"initializeGoModule was asked to instantiate a Go (builtin/extension) module after the resolver was locked — i.e. outside the initialization phase (__VU==0). The generic sentinel notPreviouslyResolvedModule fires when the module name was never pre-resolved and cached during init, typically because the import happens in handleSetup or another late lifecycle hook.","triggerScenarios":"Thrown at js/modules/resolution.go:75 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move the import of the Go module to the top of the init context (top-level import statement) so it resolves while __VU==0","Use require() inside setup only for modules already imported at the top level"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}