grafana/k6 · error

a goModule instance is of not goModuleInstance type (got…

Error message

a goModule instance is of not goModuleInstance type (got %T). This is a k6 bug please report it (https://github.com/grafana/k6/issues)

What it means

In getModuleInstanceFromGoModule, the module instance retrieved from the runtime for a goModule is not of the internal *goModuleInstance type. This breaks the module system's type invariant — an internal k6 bug in how the module instance was registered or retrieved, not a user script problem.

Solutions

  1. Update to the latest k6 version
  2. Report the issue at https://github.com/grafana/k6/issues including the script and the reported type
  3. Check for extensions that register custom modules in unusual ways
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at js/modules/require_impl.go:93 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/08a59ace3b54b7bf. Report an issue: GitHub.

Appendix: source

Thrown at js/modules/require_impl.go:93

		if err != nil {
			return nil, err
		}
		promise := rt.CyclicModuleRecordEvaluate(wm, ms.resolver.sobekModuleResolver)
		switch promise.State() {
		case sobek.PromiseStateRejected:
			err = promise.Result().Export().(error) //nolint:forcetypeassert
		case sobek.PromiseStateFulfilled:
		default:
			panic("TLA in go modules is not supported in k6 at the moment")
		}
		if err != nil {
			return nil, err
		}
		mi = rt.GetModuleInstance(wm)
	}
	gmi, ok := mi.(*goModuleInstance)
	if !ok {
		panic(fmt.Sprintf("a goModule instance is of not goModuleInstance type (got %T). "+
			"This is a k6 bug please report it (https://github.com/grafana/k6/issues)", mi))
	}
	return gmi, nil
}

// Resolve returns what the provided specifier will get resolved to if it was to be imported
// To be used by other parts to get the path
func (ms *ModuleSystem) Resolve(mr sobek.ModuleRecord, specifier string) (*url.URL, error) {
	if specifier == "" {
		return nil, errors.New("require() can't be used with an empty specifier")
	}

	baseModuleURL := ms.resolver.reversePath(mr)
	return ms.resolver.resolveSpecifier(baseModuleURL, specifier)
}

// CurrentlyRequiredModule returns the module that is currently being required.
// It is mostly used for old and somewhat buggy behaviour of the `open` call

View on GitHub (pinned to 01ffac6f24)