{"record":{"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/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/plugins/wasm.ts#L36-L72","documentation":"wasmHelper decodes a base64 'data:' URL by trying Node's Buffer.from first, then the global atob. If neither is available it throws, because it cannot turn the data URL into bytes for WebAssembly.instantiate. This path runs client-side when a wasm import resolves to an inline data URL.","triggerScenarios":"Importing a .wasm module that gets inlined as a base64 data URL, in a runtime that has neither Buffer (Node-only) nor atob (very old or non-standard JS envs). The wasmHelper is shipped as a string and evaluated in the target runtime, so it depends on those globals being present.","commonSituations":"Embedding Vite-built wasm in a restricted/legacy runtime, a custom SSR environment without Node globals, or a test runner that strips globals. Browsers have atob, so this mostly bites non-browser embedded runtimes.","solutions":["Run the wasm import in an environment that provides atob (modern browsers) or Buffer (Node).","Polyfill atob (or Buffer) in the target runtime before the wasm module loads.","Avoid inlining the wasm (so the data-URL branch is not taken) — configure assets so the wasm is emitted as a file and fetched via URL instead.","If using a custom JS runtime for SSR/tests, enable its fetch/Buffer shims."],"exampleFix":"// before — runtime lacks both Buffer and atob\n// after — polyfill atob before app code\nimport { atobPolyfill } from './atob-polyfill'\nglobalThis.atob = globalThis.atob || atobPolyfill","handlingStrategy":"type-guard","validationCode":"// Ensure decode primitives exist before app boots\nfunction assertBase64Decoders() {\n  if (typeof Buffer !== 'function' && typeof atob !== 'function') {\n    throw new Error('Polyfill Buffer or atob before loading wasm data URLs')\n  }\n}\nassertBase64Decoders()","typeGuard":"function hasBase64Decoder(): boolean {\n  return (typeof Buffer === 'function' && typeof Buffer.from === 'function') || typeof atob === 'function'\n}","tryCatchPattern":null,"preventionTips":["Target modern browsers (they have atob) or Node (Buffer) when using inlined wasm.","Polyfill atob in custom runtimes.","Avoid wasm inlining via assetsInlineLimit: 0 if your runtime lacks decoders."],"tags":["wasm","runtime","browser","polyfill"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}