{"id":"2a330175fe51f01b","repo":"vitejs/vite","slug":"failed-to-decode-base64-encoded-data-url-buffer-a","errorCode":null,"errorMessage":"Failed to decode base64-encoded data URL, Buffer and atob are not supported","messagePattern":"Failed to decode base64-encoded data URL, Buffer and atob are not supported","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/plugins/wasm.ts","lineNumber":54,"sourceCode":"  ...wasmCompileOptions.builtins.map((name) => `wasm:${name}`),\n  wasmCompileOptions.importedStringConstants,\n])\n\nconst wasmHelper = async (opts = {}, url: string) => {\n  let result\n  if (url.startsWith('data:')) {\n    const urlContent = url.replace(/^data:.*?base64,/, '')\n    let bytes\n    if (typeof Buffer === 'function' && typeof Buffer.from === 'function') {\n      bytes = Buffer.from(urlContent, 'base64')\n    } else if (typeof atob === 'function') {\n      const binaryString = atob(urlContent)\n      bytes = new Uint8Array(binaryString.length)\n      for (let i = 0; i < binaryString.length; i++) {\n        bytes[i] = binaryString.charCodeAt(i)\n      }\n    } else {\n      throw new Error(\n        'Failed to decode base64-encoded data URL, Buffer and atob are not supported',\n      )\n    }\n    result = await WebAssembly.instantiate(bytes, opts, wasmCompileOptions)\n  } else {\n    result = await instantiateFromUrl(url, opts)\n  }\n  return result.instance\n}\n\nconst wasmHelperCode = wasmHelper.toString()\n\nconst instantiateFromUrl = async (url: string, opts?: WebAssembly.Imports) => {\n  // https://github.com/mdn/webassembly-examples/issues/5\n  // WebAssembly.instantiateStreaming requires the server to provide the\n  // correct MIME type for .wasm files, which unfortunately doesn't work for\n  // a lot of static file servers, so we just work around it by getting the\n  // raw buffer.","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/plugins/wasm.ts#L36-L72","documentation":"The wasm runtime helper (wasmHelper at packages/vite/src/node/plugins/wasm.ts:54) decodes a `data:` base64 wasm URL at runtime. It first tries Node's Buffer.from, then browser global atob; if neither exists it throws. This is glue code shipped into the built bundle, so the error fires in whatever runtime consumes the output (an unusual JS engine, a sandbox, or an older browser without atob).","triggerScenarios":"Inlining a small .wasm as a data: URL (asset inlining under assetsInlineLimit) and running the output in a JS environment that has neither Node's Buffer nor window.atob (e.g. QuickJS, a restricted Worker, an embedded JS engine, or IE/old Safari).","commonSituations":"Targeting obscure/edge runtimes with inlined wasm; SSR/edge workers that strip Node globals; very small wasm modules that get auto-inlined and then run in a minimal sandbox.","solutions":["Raise build.assetsInlineLimit below the size of the .wasm file so Vite emits it as a real file URL fetched via instantiateFromUrl/instantiateFromFile instead of a data: URL.","Run the output in an environment that provides atob (browsers) or Buffer (Node) — add the appropriate polyfill if you control the runtime.","Load the wasm yourself with WebAssembly.instantiateStreaming from a fetched file instead of relying on Vite's ?init helper."],"exampleFix":"// before: wasm inlined as data URL, fails in minimal runtime\nexport default defineConfig({})\n\n// after: keep wasm as a file asset so no base64 decode is needed\nexport default defineConfig({\n  build: { assetsInlineLimit: 0 },\n})","handlingStrategy":"validation","validationCode":"function runtimeCanDecodeBase64(): boolean {\n  return typeof Buffer === 'function' || typeof atob === 'function'\n}\nif (wasmIsInlinedAsDataUrl && !runtimeCanDecodeBase64()) {\n  throw new Error('target runtime cannot decode inlined wasm; raise assetsInlineLimit')\n}","typeGuard":"function hasBase64Decoder(): boolean {\n  return typeof Buffer === 'function' || typeof atob === 'function'\n}","tryCatchPattern":null,"preventionTips":["Set build.assetsInlineLimit below the size of any .wasm so wasm is emitted as a file, not inlined.","Confirm the target runtime exposes atob (browsers) or Buffer (Node).","Prefer fetch + WebAssembly.instantiateStreaming over ?init inlining when targeting minimal runtimes."],"tags":["wasm","runtime","asset-inline","browser-support"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}