{"id":"9852ea8a9055fad6","repo":"vitest-dev/vitest","slug":"invalid-data-uri-encoding-encoding","errorCode":null,"errorMessage":"Invalid data URI encoding: ${encoding}","messagePattern":"Invalid data URI encoding: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/vm/esm-executor.ts","lineNumber":216,"sourceCode":"      return cached\n    }\n\n    const match = identifier.match(dataURIRegex)\n\n    if (!match || !match.groups) {\n      throw new Error('Invalid data URI')\n    }\n\n    const mime = match.groups.mime\n    const encoding = match.groups.encoding\n\n    if (mime === 'application/wasm') {\n      if (!encoding) {\n        throw new Error('Missing data URI encoding')\n      }\n\n      if (encoding !== 'base64') {\n        throw new Error(`Invalid data URI encoding: ${encoding}`)\n      }\n\n      const module = this.loadWebAssemblyModule(\n        Buffer.from(match.groups.code, 'base64'),\n        identifier,\n      )\n      this.moduleCache.set(identifier, module)\n      return module\n    }\n\n    let code = match.groups.code\n    if (!encoding || encoding === 'charset=utf-8') {\n      code = decodeURIComponent(code)\n    }\n    else if (encoding === 'base64') {\n      code = Buffer.from(code, 'base64').toString()\n    }\n    else {","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/vm/esm-executor.ts#L198-L234","documentation":"Thrown by createDataModule when a `data:application/wasm` URI has an encoding segment that is not `base64`. The wasm branch only accepts base64 (line 215-216); any other encoding value such as `charset=utf-8` is rejected because wasm bytes cannot be represented that way through this path.","triggerScenarios":"Importing `data:application/wasm;charset=utf-8,<text>` or `data:application/wasm;charset=ascii,<text>`. The encoding group matched but its value is not base64.","commonSituations":"Defaulting to charset=utf-8 for all data URIs including wasm. A template that appends charset=utf-8 unconditionally. Copying a JS/JSON data URI template for wasm.","solutions":["Use `;base64` for wasm data URIs and base64-encode the binary payload.","Remove a stray charset=utf-8 from the wasm URI.","Load wasm from a fixture file instead of a data URI."],"exampleFix":"// before\nimport wasm from 'data:application/wasm;charset=utf-8,AGFzbQ'\n\n// after\nimport wasm from 'data:application/wasm;base64,AGFzbQ=='","handlingStrategy":"validation","validationCode":"function assertWasmEncoding(uri: string) {\n  const m = uri.match(/^data:application\\/wasm;([^,]+),/)\n  if (m && m[1] !== 'base64') throw new Error(`wasm data URI encoding must be base64, got ${m[1]}`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use exactly `;base64` for application/wasm data URIs.","Do not append charset=utf-8 to wasm data URIs.","Generate wasm data URIs from a Buffer via base64."],"tags":["data-uri","wasm","esm","vm"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}