{"record":{"id":"75a0b833ff6d2b95","repo":"vitest-dev/vitest","slug":"invalid-data-uri","errorCode":null,"errorMessage":"Invalid data URI","messagePattern":"Invalid data URI","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/vm/esm-executor.ts","lineNumber":39,"sourceCode":"// modules); `commit` marks modules the walk owns and should commit to the\n// cache — false for cache hits and modules owned by the CJS executor.\ntype ScratchEntry\n  = | { module: VMModule; deps?: undefined; commit: boolean }\n    | { module: VMSourceTextModule; deps: string[]; commit: true }\n\n// `hasAsyncGraph` only exists on SourceTextModule — a SyntheticModule is\n// synchronous by definition (its evaluation callback is sync)\nfunction moduleHasAsyncGraph(module: VMModule): boolean {\n  return module instanceof SourceTextModule && module.hasAsyncGraph()\n}\n\nconst dataURIRegex\n  = /^data:(?<mime>text\\/javascript|application\\/json|application\\/wasm)(?:;(?<encoding>charset=utf-8|base64))?,(?<code>.*)$/\n\nfunction parseDataUri(identifier: string): { mime: string; code: string | Buffer } {\n  const match = identifier.match(dataURIRegex)\n  if (!match || !match.groups) {\n    throw new Error('Invalid data URI')\n  }\n  const { mime, encoding } = match.groups\n  let code: string | Buffer = match.groups.code\n  if (mime === 'application/wasm') {\n    if (!encoding) {\n      throw new Error('Missing data URI encoding')\n    }\n    if (encoding !== 'base64') {\n      throw new Error(`Invalid data URI encoding: ${encoding}`)\n    }\n    return { mime, code: Buffer.from(code, 'base64') }\n  }\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  }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/runtime/vm/esm-executor.ts#L21-L57","documentation":"Thrown by parseDataUri when a `data:` URI imported by test code does not match the strict regex requiring a MIME of text/javascript, application/json, or application/wasm, an optional encoding of charset=utf-8 or base64, and a trailing code segment. Any other scheme, MIME, or malformed structure fails here.","triggerScenarios":"A test (or its dependency graph) imports a `data:` URI with an unsupported MIME (e.g. `data:text/plain,...`, `data:image/png;base64,...`), a missing comma before the payload, or a syntactically broken URI. Reached via EsmExecutor.createDataModule and the sync data-module path.","commonSituations":"Bundlers/tools emitting `data:` URIs for assets (CSS, images) that Vitest's data-URI handler does not recognize; hand-written data imports with a wrong MIME; a transform producing a malformed data URI.","solutions":["Use a supported MIME: `data:text/javascript,...`, `data:application/json,...`, or `data:application/wasm;base64,...`.","Ensure the URI has a comma separating the header from the payload.","For non-JS assets, configure Vite/Vitest to transform or inline them rather than emitting an unsupported data URI.","If the URI is generated by a plugin, update the plugin to emit a supported MIME or a real file URL."],"exampleFix":"// before\nimport val from 'data:text/plain,hello'\n\n// after\nimport val from 'data:application/json,' + encodeURIComponent(JSON.stringify('hello'))","handlingStrategy":"validation","validationCode":"const DATA_URI_RE = /^data:(?:text\\/javascript|application\\/json|application\\/wasm)(?:;(?:charset=utf-8|base64))?,.*$/\nfunction isSupportedDataUri(uri: string): boolean {\n  return DATA_URI_RE.test(uri)\n}","typeGuard":"function isSupportedDataUri(uri: string): boolean {\n  return /^data:(?:text\\/javascript|application\\/json|application\\/wasm)(?:;(?:charset=utf-8|base64))?,.+$/s.test(uri)\n}","tryCatchPattern":null,"preventionTips":["Only import JS, JSON, or wasm data URIs in test code.","Configure Vite to handle non-JS assets rather than emitting unsupported data URIs.","Validate generated data URIs against the supported MIME list before import."],"tags":["vm","esm","data-uri","imports","validation"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}