{"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":204,"sourceCode":"\n  public cacheModule(identifier: string, module: VMModule): void {\n    this.moduleCache.set(identifier, module)\n  }\n\n  public resolveCachedModule(identifier: string): VMModule | Promise<VMModule> | undefined {\n    return this.moduleCache.get(identifier)\n  }\n\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      )","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/vm/esm-executor.ts#L186-L222","documentation":"Thrown by EsmExecutor.createDataModule when a `data:` URI identifier does not match the supported regex (which allows mime text/javascript, application/json, or application/wasm, optionally with charset=utf-8 or base64, followed by the payload). Any data URI with an unsupported mime, a malformed structure, or no captured groups fails here.","triggerScenarios":"Importing a `data:` URI whose MIME type is not one of text/javascript, application/json, or application/wasm (e.g. `data:text/plain,...` or `data:application/javascript,...` - note the regex requires exactly text/javascript). A URI missing the `data:` scheme or the comma. A URI with a mime but empty payload that still fails the regex.","commonSituations":"Using a non-standard mime like `application/javascript` (the regex only allows `text/javascript`). Constructing data URIs by hand and getting the mime wrong. Importing JSON with `data:application/json` but missing the comma/payload.","solutions":["Use one of the supported MIME types: `text/javascript`, `application/json`, or `application/wasm`.","Ensure the URI is well-formed: `data:<mime>[;<encoding>],<payload>`.","For JavaScript, prefer `data:text/javascript,console.log(1)` (plain) or `;base64,` form.","Move the payload into a fixture file and import it normally if the data URI keeps failing."],"exampleFix":"// before\nimport code from 'data:application/javascript,console.log(1)'\n\n// after\nimport code from 'data:text/javascript,console.log(1)'","handlingStrategy":"validation","validationCode":"const DATA_URI = /^data:(?:text\\/javascript|application\\/json|application\\/wasm)(?:;(?:charset=utf-8|base64))?,.*$/\nfunction isValidDataUri(uri: string): boolean {\n  return DATA_URI.test(uri)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only text/javascript, application/json, or application/wasm mimes in data URIs.","Generate data URIs with a helper that emits the supported mime.","Prefer fixture files over data URIs for non-trivial payloads."],"tags":["data-uri","esm","vm"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}