{"record":{"id":"4d92e2c2b2baa9cd","repo":"golang/go","slug":"globalthis-textdecoder-is-not-available-polyfill","errorCode":null,"errorMessage":"globalThis.TextDecoder is not available, polyfill required","messagePattern":"globalThis\\.TextDecoder is not available, polyfill required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"lib/wasm/wasm_exec.js","lineNumber":97,"sourceCode":"\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) => {\n\t\t\t\tif (code !== 0) {\n\t\t\t\t\tconsole.warn(\"exit code:\", code);\n\t\t\t\t}\n\t\t\t};\n\t\t\tthis._exitPromise = new Promise((resolve) => {\n\t\t\t\tthis._resolveExitPromise = resolve;\n\t\t\t});\n\t\t\tthis._pendingEvent = null;","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/lib/wasm/wasm_exec.js#L79-L115","documentation":"Thrown by wasm_exec.js when globalThis.TextDecoder is missing at load time. TextDecoder turns UTF-8 bytes read from Go wasm memory back into JS strings. Like the other polyfill gates, it fires during module initialization, before go.run() can be invoked.","triggerScenarios":"Loading wasm_exec.js in a runtime lacking the Encoding Living Standard TextDecoder: old Node (< 11), minimal embedded engines, vm contexts without inherited globals.","commonSituations":"Calling Go wasm from legacy Node; running in a locked-down VM sandbox; using a JS engine whose text-encoding module is opt-in.","solutions":["Use Node.js >= 11 where TextDecoder is a global.","Polyfill: globalThis.TextDecoder = require('node:util').TextDecoder; before requiring wasm_exec.js.","Use the text-encoding polyfill package: globalThis.TextDecoder = require('text-encoding').TextDecoder;.","Propagate TextDecoder into any vm.createContext sandbox explicitly."],"exampleFix":"// before\nrequire('./wasm_exec.js'); // throws: globalThis.TextDecoder is not available\n\n// after\nconst { TextDecoder } = require('node:util');\nglobalThis.TextDecoder = TextDecoder;\nrequire('./wasm_exec.js');","handlingStrategy":"validation","validationCode":"if (typeof globalThis.TextDecoder === 'undefined') {\n  globalThis.TextDecoder = require('node:util').TextDecoder;\n}","typeGuard":"const hasTextDecoder = () => typeof globalThis.TextDecoder === 'function';","tryCatchPattern":null,"preventionTips":["Use Node >= 11 (TextDecoder is global).","Add TextDecoder to your bootstrap polyfill module.","Inject TextDecoder into vm.createContext sandboxes explicitly."],"tags":["wasm","go","textdecoder","polyfill","runtime","environment"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}