{"record":{"id":"afaa0821f0536cfa","repo":"golang/go","slug":"globalthis-performance-is-not-available-polyfill","errorCode":null,"errorMessage":"globalThis.performance is not available, polyfill required (performance.now only)","messagePattern":"globalThis\\.performance is not available, polyfill required \\(performance\\.now only\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"lib/wasm/wasm_exec.js","lineNumber":89,"sourceCode":"\t\t\tcwd() { throw enosys(); },\n\t\t\tchdir() { throw enosys(); },\n\t\t}\n\t}\n\n\tif (!globalThis.path) {\n\t\tglobalThis.path = {\n\t\t\tresolve(...pathSegments) {\n\t\t\t\treturn pathSegments.join(\"/\");\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!globalThis.crypto) {\n\t\tthrow new Error(\"globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)\");\n\t}\n\n\tif (!globalThis.performance) {\n\t\tthrow new Error(\"globalThis.performance is not available, polyfill required (performance.now only)\");\n\t}\n\n\tif (!globalThis.TextEncoder) {\n\t\tthrow new Error(\"globalThis.TextEncoder is not available, polyfill required\");\n\t}\n\n\tif (!globalThis.TextDecoder) {\n\t\tthrow new Error(\"globalThis.TextDecoder is not available, polyfill required\");\n\t}\n\n\tconst encoder = new TextEncoder(\"utf-8\");\n\tconst decoder = new TextDecoder(\"utf-8\");\n\n\tglobalThis.Go = class {\n\t\tconstructor() {\n\t\t\tthis.argv = [\"js\"];\n\t\t\tthis.env = {};\n\t\t\tthis.exit = (code) => {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/lib/wasm/wasm_exec.js#L71-L107","documentation":"Thrown by wasm_exec.js when globalThis.performance is absent at load time. The Go wasm runtime uses performance.now() for its clock source (timers, runtime.nanotime). This is a startup self-check that fires before any Go code runs, so the failure is always at module evaluation, not later.","triggerScenarios":"Loading wasm_exec.js in a JS engine with no High Resolution Time API: QuickJS without the perf module, very old Node (< 8), a `vm.createContext` that did not copy performance, or a minimal embedded runtime.","commonSituations":"Bundling Go wasm for a non-browser target and forgetting to polyfill timing; running tests in a sandboxed JS interpreter; migrating a Go-wasm worker from browser (which has performance) to a minimal Node script (older versions).","solutions":["Use Node.js >= 8, where globalThis.performance is available.","Polyfill before loading wasm_exec.js: const { performance } = require('node:perf_hooks'); globalThis.performance = performance;","Minimal fallback: globalThis.performance = { now: () => Date.now() }; (lower resolution, acceptable for non-benchmarking use).","If using a VM context, inject performance explicitly via the contextified sandbox object."],"exampleFix":"// before\nrequire('./wasm_exec.js'); // throws: globalThis.performance is not available\n\n// after\nconst { performance } = require('node:perf_hooks');\nglobalThis.performance = performance;\nrequire('./wasm_exec.js');","handlingStrategy":"validation","validationCode":"if (typeof globalThis.performance === 'undefined' || typeof globalThis.performance.now !== 'function') {\n  const { performance } = require('node:perf_hooks');\n  globalThis.performance = performance;\n}","typeGuard":"const hasPerformance = () => typeof globalThis.performance === 'object' && globalThis.performance !== null && typeof globalThis.performance.now === 'function';","tryCatchPattern":null,"preventionTips":["Run on Node >= 8 (performance is global).","Keep a bootstrap module that polyfills performance before wasm_exec.js is required.","For vm contexts, inject performance explicitly into the contextified sandbox."],"tags":["wasm","go","performance","polyfill","runtime","environment"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}