grafana/k6 · error

k6/experimental/webcrypto has been graduated and it's now…

Error message

k6/experimental/webcrypto has been graduated and it's now globally available as defined by standard WebAPIs. You just need to remove the import.

What it means

The k6/experimental/webcrypto module graduated: the WebCrypto API (crypto.subtle, crypto.getRandomValues, etc.) is now a global standard WebAPI inside every k6 script. The old import path is mapped to a stub module that always throws (newRemovedModule, internal/js/jsmodules.go:98-110), so importing it aborts script initialization. No functionality was lost, only the import must go.

Solutions

  1. Delete the import line and use the global `crypto` object directly (crypto.subtle.digest, crypto.subtle.sign, crypto.getRandomValues, etc.)
  2. If the import is re-exported by a shared helper file, update that file and every script that imports it
  3. As a temporary stopgap, pin CI to the last k6 version that still aliases the module (not recommended)

Example fix

// before
import { crypto } from 'k6/experimental/webcrypto';
const digest = await crypto.subtle.digest('SHA-256', data);

// after
const digest = await crypto.subtle.digest('SHA-256', data); // crypto is global
Defensive patterns

Strategy: validation

Validate before calling

# CI pre-flight: the old import must be gone before k6 starts
if grep -rn "k6/experimental/webcrypto" scripts/ lib/; then
  echo "ERROR: crypto is now a global WebAPI; delete the webcrypto import" >&2
  exit 1
fi

// in-script sanity check (k6 >= the graduating release):
if (typeof crypto === 'undefined' || !crypto.subtle) throw new Error('global crypto unavailable; check k6 version');

Prevention

When it happens

Trigger: A script contains `import { crypto } from 'k6/experimental/webcrypto'` (or `import crypto from 'k6/experimental/webcrypto'`) and runs on a k6 version where WebCrypto became global. The throw happens at module instantiation time, before the script body runs.

Common situations: Upgrading k6 (v0.5x to v1.x) with scripts that hashed, signed, or generated keys via webcrypto; copied boilerplate from older blog posts; xk6 extensions or shared jslib files that re-export the experimental import.

Related errors


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

Appendix: source

Thrown at internal/js/jsmodules.go:107

	// external is always prefixed with `k6/x`
	for _, e := range external {
		result[e.Name] = e.Module
	}

	return result
}

type removedModule struct {
	errMsg string
}

func newRemovedModule(errMsg string) modules.Module {
	return &removedModule{errMsg: errMsg}
}

func (rm *removedModule) NewModuleInstance(vu modules.VU) modules.Instance {
	common.Throw(vu.Runtime(), errors.New(rm.errMsg))

	return nil
}

type warnExperimentalModule struct {
	once sync.Once
	msg  string
	base modules.Module
}

func newWarnExperimentalModule(base modules.Module, msg string) modules.Module {
	return &warnExperimentalModule{
		msg:  msg,
		base: base,
	}
}

func (w *warnExperimentalModule) NewModuleInstance(vu modules.VU) modules.Instance {

View on GitHub (pinned to 01ffac6f24)