vitest-dev/vitest · error · Error
Missing data URI encoding
Error message
Missing data URI encoding
What it means
Thrown by parseDataUri specifically for WebAssembly data URIs: when the MIME is `application/wasm` the encoding is mandatory (only base64 wasm is supported, because raw binary cannot live in a text URI). Reaching this branch means a wasm data URI had no `;base64` (or any encoding) segment.
Solutions
- Encode the wasm as base64 and add `;base64`: `data:application/wasm;base64,<base64-bytes>`.
- Load the wasm from a file URL instead of a data URI when feasible.
- When generating URIs in code, always pair `application/wasm` with base64 encoding.
Example fix
// before
const url = `data:application/wasm,${rawBytes}`
// after
const url = `data:application/wasm;base64,${rawBytes.toString('base64')}` Defensive patterns
Strategy: validation
Validate before calling
function isBase64WasmDataUri(uri: string): boolean {
return /^data:application\/wasm;base64,[A-Za-z0-9+/=]+$/.test(uri)
} Type guard
function isBase64WasmDataUri(uri: string): boolean {
return /^data:application\/wasm;base64,[A-Za-z0-9+/=]+$/.test(uri)
} Prevention
- Always pair `application/wasm` with `;base64` in generated URIs.
- Prefer loading wasm from file: URLs to avoid encoding mistakes.
- Unit-test URI generators to confirm they emit base64 for wasm.
When it happens
Trigger: Test code imports `data:application/wasm,<binary>` without an encoding, e.g. `await import('data:application/wasm,AGFzbQ...')`. Vitest requires `data:application/wasm;base64,...` so the bytes decode reliably.
Common situations: Generating wasm data URIs programmatically and forgetting the base64 encoding; copy-pasting a wasm data URI that omitted the encoding; tools that emit raw wasm bytes inline.
Related errors
- Invalid data URI encoding
- Invalid data URI
- Cannot import " ": its vm context was torn down.
- invalid diff config file
- invalid snapshot serializer file
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/18b60fa34aff1b2d.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/runtime/vm/esm-executor.ts:45
// `hasAsyncGraph` only exists on SourceTextModule — a SyntheticModule is
// synchronous by definition (its evaluation callback is sync)
function moduleHasAsyncGraph(module: VMModule): boolean {
return module instanceof SourceTextModule && module.hasAsyncGraph()
}
const dataURIRegex
= /^data:(?<mime>text\/javascript|application\/json|application\/wasm)(?:;(?<encoding>charset=utf-8|base64))?,(?<code>.*)$/
function parseDataUri(identifier: string): { mime: string; code: string | Buffer } {
const match = identifier.match(dataURIRegex)
if (!match || !match.groups) {
throw new Error('Invalid data URI')
}
const { mime, encoding } = match.groups
let code: string | Buffer = match.groups.code
if (mime === 'application/wasm') {
if (!encoding) {
throw new Error('Missing data URI encoding')
}
if (encoding !== 'base64') {
throw new Error(`Invalid data URI encoding: ${encoding}`)
}
return { mime, code: Buffer.from(code, 'base64') }
}
if (!encoding || encoding === 'charset=utf-8') {
code = decodeURIComponent(code)
}
else if (encoding === 'base64') {
code = Buffer.from(code, 'base64').toString()
}
else {
throw new Error(`Invalid data URI encoding: ${encoding}`)
}
return { mime, code }
}
View on GitHub (pinned to 1fa9837ec2)