{"id":"18b60fa34aff1b2d","repo":"vitest-dev/vitest","slug":"missing-data-uri-encoding","errorCode":null,"errorMessage":"Missing data URI encoding","messagePattern":"Missing data URI encoding","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/vm/esm-executor.ts","lineNumber":212,"sourceCode":"\n  public async createDataModule(identifier: string): Promise<VMModule> {\n    const cached = this.moduleCache.get(identifier)\n    if (cached) {\n      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    }","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/vm/esm-executor.ts#L194-L230","documentation":"Thrown by createDataModule when a `data:application/wasm,...` URI is imported but has no encoding segment. WebAssembly data URIs require base64 encoding (raw binary wasm cannot be embedded as URI-encoded text safely), so the wasm branch insists on an explicit `;base64`.","triggerScenarios":"Importing `data:application/wasm,<bytes>` without the `;base64` encoding marker. The wasm code path runs only for the application/wasm mime, and the encoding group is empty/undefined.","commonSituations":"Hand-constructing a wasm data URI and forgetting the encoding. Tooling that emits data URIs without the encoding field for binary payloads.","solutions":["Add `;base64` to the wasm data URI and base64-encode the binary payload.","Load the wasm from a file instead: import the bytes and use WebAssembly.compile, or use createWebAssemblyModule with a Buffer.","Generate the data URI with a library that always emits the encoding segment."],"exampleFix":"// before\nimport wasm from 'data:application/wasm,AGFzbQ...'\n\n// after\nimport wasm from 'data:application/wasm;base64,AGFzbQ=='","handlingStrategy":"validation","validationCode":"function assertWasmDataUri(uri: string) {\n  const m = uri.match(/^data:application\\/wasm;([^,]+),/)\n  if (m && m[1] !== 'base64') throw new Error('wasm data URI must use ;base64')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always embed wasm bytes as base64 in data URIs.","Load wasm from a fixture file to avoid manual URI construction.","Validate the encoding segment is present for application/wasm."],"tags":["data-uri","wasm","esm","vm"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}