{"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/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/vm/vite-executor.ts#L50-L86","documentation":"Thrown by ViteExecutor.createViteModule when the VM pool asks Vite (via RPC transform) to compile a module URL but receives no transformed code back. It is the fallback error after the transform either returns an empty result or throws an error that is not a module-load failure. This indicates the file URL could not be resolved/transformed by the Vite server inside the VM worker.","triggerScenarios":"Running tests with a VM pool (vmThreads/vmForks) where a test file or one of its imports resolves to a file URL that Vite's transform pipeline cannot process. The code path is: createViteModule -> this.options.transform(fileUrl) returns result with no `code`, OR transform throws a non-ERR_LOAD_URL error, then execution falls through to line 68.","commonSituations":"Importing a file path that does not exist on disk (typo), importing a file outside the Vite project root without configuring server.fs.allow, a Vite plugin whose transform hook throws, or a case-sensitivity mismatch in the import path on case-sensitive filesystems.","solutions":["Verify the file at the reported fileUrl actually exists on disk (check spelling, case, extension).","Ensure the file is inside the Vite project root or that server.fs.allow includes its directory in your Vitest config.","Run Vite with debug logging (DEBUG=vite:*) to see why the transform returned no code.","Check that any custom Vite plugins' transform hooks do not throw or swallow the code for that file type."],"exampleFix":"// before: importing a non-existent/typo path\nimport helper from './src/helpers/tils.ts' // 'utils' misspelled\n\n// after: correct the path\nimport helper from './src/helpers/utils.ts'","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nfunction assertImportResolvable(importSpecifier: string, root: string) {\n  if (importSpecifier.startsWith('.') || importSpecifier.startsWith('/')) {\n    const target = resolve(root, importSpecifier)\n    if (!existsSync(target)) {\n      throw new Error(`Cannot resolve import '${importSpecifier}' from root '${root}'`)\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Lint test imports with a resolver rule (e.g. eslint-plugin-import no-unresolved) so typos fail before runtime.","Keep test fixtures inside the Vite root and list external roots in server.fs.allow.","When using a VM pool, prefer absolute file URLs in dynamic imports to avoid ambiguous resolution."],"tags":["vm-pool","vite","module-resolution","transform"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}