{"record":{"id":"dc876812fc808b24","repo":"grafana/k6","slug":"k6-experimental-webcrypto-has-been-graduated-and-i","errorCode":null,"errorMessage":"k6/experimental/webcrypto has been graduated and it's now globally available as defined by standard WebAPIs. You just need to remove the import.","messagePattern":"k6/experimental/webcrypto has been graduated and it's now globally available as defined by standard WebAPIs\\. You just need to remove the import\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/jsmodules.go","lineNumber":107,"sourceCode":"\n\t// external is always prefixed with `k6/x`\n\tfor _, e := range external {\n\t\tresult[e.Name] = e.Module\n\t}\n\n\treturn result\n}\n\ntype removedModule struct {\n\terrMsg string\n}\n\nfunc newRemovedModule(errMsg string) modules.Module {\n\treturn &removedModule{errMsg: errMsg}\n}\n\nfunc (rm *removedModule) NewModuleInstance(vu modules.VU) modules.Instance {\n\tcommon.Throw(vu.Runtime(), errors.New(rm.errMsg))\n\n\treturn nil\n}\n\ntype warnExperimentalModule struct {\n\tonce sync.Once\n\tmsg  string\n\tbase modules.Module\n}\n\nfunc newWarnExperimentalModule(base modules.Module, msg string) modules.Module {\n\treturn &warnExperimentalModule{\n\t\tmsg:  msg,\n\t\tbase: base,\n\t}\n}\n\nfunc (w *warnExperimentalModule) NewModuleInstance(vu modules.VU) modules.Instance {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/jsmodules.go#L89-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Delete the import line and use the global `crypto` object directly (crypto.subtle.digest, crypto.subtle.sign, crypto.getRandomValues, etc.)","If the import is re-exported by a shared helper file, update that file and every script that imports it","As a temporary stopgap, pin CI to the last k6 version that still aliases the module (not recommended)"],"exampleFix":"// before\nimport { crypto } from 'k6/experimental/webcrypto';\nconst digest = await crypto.subtle.digest('SHA-256', data);\n\n// after\nconst digest = await crypto.subtle.digest('SHA-256', data); // crypto is global","handlingStrategy":"validation","validationCode":"# CI pre-flight: the old import must be gone before k6 starts\nif grep -rn \"k6/experimental/webcrypto\" scripts/ lib/; then\n  echo \"ERROR: crypto is now a global WebAPI; delete the webcrypto import\" >&2\n  exit 1\nfi\n\n// in-script sanity check (k6 >= the graduating release):\nif (typeof crypto === 'undefined' || !crypto.subtle) throw new Error('global crypto unavailable; check k6 version');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the global crypto object directly in new code; never import a WebAPI that is standard","Keep shared js helper files free of k6/experimental/* re-exports","Pin k6 versions in CI and upgrade deliberately after checking release notes","Run a smoke 'k6 run' of one representative script in CI on any k6 version bump"],"tags":["k6","webcrypto","crypto","module-migration","breaking-change","import"],"backgroundTag":"removed-module-import","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}