{"record":{"id":"8027a05a6aaac098","repo":"vitest-dev/vitest","slug":"vitest-failed-to-transform-fileurl-does-the","errorCode":null,"errorMessage":"[vitest] Failed to transform ${fileUrl}. Does the file exist?","messagePattern":"\\[vitest\\] Failed to transform (.+?)\\. Does the file exist\\?","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/vm/vite-executor.ts","lineNumber":68,"sourceCode":"          return result.code\n        }\n      }\n      catch (cause: any) {\n        // rethrow vite error if it cannot load the module because it's not resolved\n        if (\n          (typeof cause === 'object' && cause.code === 'ERR_LOAD_URL')\n          || (typeof cause?.message === 'string' && cause.message.includes('Failed to load url'))\n        ) {\n          const error = new Error(\n            `Cannot find module '${fileUrl}'`,\n            { cause },\n          ) as Error & { code: string }\n          error.code = 'ERR_MODULE_NOT_FOUND'\n          throw error\n        }\n      }\n\n      throw new Error(\n        `[vitest] Failed to transform ${fileUrl}. Does the file exist?`,\n      )\n    })\n  }\n\n  private createViteClientModule() {\n    const identifier = CLIENT_ID\n    const cached = this.esm.resolveCachedModule(identifier)\n    if (cached) {\n      return cached\n    }\n    const stub = this.options.viteClientModule\n    const moduleKeys = Object.keys(stub)\n    const module = new SyntheticModule(\n      moduleKeys,\n      function () {\n        moduleKeys.forEach((key) => {\n          this.setExport(key, stub[key])","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/runtime/vm/vite-executor.ts#L50-L86","documentation":"ViteExecutor.fetchTransformResult asks Vite to transform a module URL; if the result returns no code and the underlying error is not recognized as a module-not-found (ERR_LOAD_URL / 'Failed to load url'), it falls through to this generic 'Failed to transform ... Does the file exist?' error. It is the catch-all for transform failures that are not specifically missing-module errors.","triggerScenarios":"The vm executor calls Vite's transformRequest for fileUrl and receives neither code nor a recognized not-found error. This covers genuine missing files where Vite did not surface ERR_MODULE_NOT_FOUND, plus plugin errors, syntax errors, or resolve failures inside the transform pipeline.","commonSituations":"Importing a file that does not exist on disk, a path alias misconfiguration, a Vite plugin throwing during transform, or a file with a syntax error that Vite could not parse. The 'Does the file exist?' hint points at the missing-file case as the most common.","solutions":["Verify the file at fileUrl actually exists on disk and the import path/alias resolves to it.","Run the same import through Vite directly or with test.pool='threads' to surface the real transform error.","Check vitest.config aliases (resolve.alias) and tsconfig paths match the import.","Disable suspect Vite plugins temporarily to isolate a transform-time plugin failure."],"exampleFix":"// before: alias misconfigured\nimport { x } from '@/utils/missing'\n\n// after: correct alias / existing file\nimport { x } from '@/utils/exists'","handlingStrategy":"try-catch","validationCode":"import { existsSync } from 'node:fs'\nimport { pathToFileURL } from 'node:url'\nfunction fileExists(url) {\n  try { return existsSync(new URL(url)) } catch { return false }\n}\nif (!fileExists(fileUrl)) throw new Error('file missing: ' + fileUrl)","typeGuard":null,"tryCatchPattern":"try {\n  await viteExecutor.fetchTransformResult(fileUrl)\n} catch (e) {\n  if (/Failed to transform/.test(e.message)) {\n    // check disk, aliases, plugins; re-run with threads pool for detail\n  }\n  throw e\n}","preventionTips":["Validate import paths and aliases before running tests.","Run the failing import through Vite directly to see the real transform error.","Keep resolve.alias and tsconfig paths in sync."],"tags":["vite","transform","missing-file","vm","resolve"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}