vitest-dev/vitest · error · Error
Missing data URI encoding
Error message
Missing data URI encoding
What it means
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`.
Source
Thrown at packages/vitest/src/runtime/vm/esm-executor.ts:212
public async createDataModule(identifier: string): Promise<VMModule> {
const cached = this.moduleCache.get(identifier)
if (cached) {
return cached
}
const match = identifier.match(dataURIRegex)
if (!match || !match.groups) {
throw new Error('Invalid data URI')
}
const mime = match.groups.mime
const encoding = match.groups.encoding
if (mime === 'application/wasm') {
if (!encoding) {
throw new Error('Missing data URI encoding')
}
if (encoding !== 'base64') {
throw new Error(`Invalid data URI encoding: ${encoding}`)
}
const module = this.loadWebAssemblyModule(
Buffer.from(match.groups.code, 'base64'),
identifier,
)
this.moduleCache.set(identifier, module)
return module
}
let code = match.groups.code
if (!encoding || encoding === 'charset=utf-8') {
code = decodeURIComponent(code)
}View on GitHub (pinned to d568f8ce37)
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.
Example fix
// before import wasm from 'data:application/wasm,AGFzbQ...' // after import wasm from 'data:application/wasm;base64,AGFzbQ=='
Defensive patterns
Strategy: validation
Validate before calling
function assertWasmDataUri(uri: string) {
const m = uri.match(/^data:application\/wasm;([^,]+),/)
if (m && m[1] !== 'base64') throw new Error('wasm data URI must use ;base64')
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Hand-constructing a wasm data URI and forgetting the encoding. Tooling that emits data URIs without the encoding field for binary payloads.
Related errors
- Invalid data URI encoding: ${encoding}
- Invalid data URI
- import of '${fileUrl}' by undefined is not supported: http c
- Expected IP address, received ${address}
- Cannot parse the module format of '${url}' because "module.f
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/18b60fa34aff1b2d.json.
Report an issue: GitHub.