{"id":"f766d446df79aaac","repo":"vitest-dev/vitest","slug":"root-path-does-not-exist-or-is-not-a-directory","errorCode":null,"errorMessage":"Root path does not exist or is not a directory: ${resolved.root}","messagePattern":"Root path does not exist or is not a directory: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/config/resolveConfig.ts","lineNumber":222,"sourceCode":"\n    options.environment = 'happy-dom'\n  }\n\n  const resolved = deepMerge({}, configDefaults, options) as ResolvedConfig\n  resolved.root = viteConfig.root\n\n  // These options are resolved once for the whole run using the root config.\n  // Coverage is shared by reference: each project's setup/test/config files are\n  // appended to the same exclude list below, keeping them out of the report.\n  if (globalConfig) {\n    resolved.coverage = globalConfig.coverage\n    resolved.attachmentsDir = globalConfig.attachmentsDir\n    resolved.mergeReportsLabel = globalConfig.mergeReportsLabel\n  }\n\n  const rootStats = statSync(resolved.root, { throwIfNoEntry: false })\n  if (!rootStats?.isDirectory()) {\n    throw new Error(`Root path does not exist or is not a directory: ${resolved.root}`)\n  }\n\n  resolved.mode ??= viteConfig.mode ?? 'test'\n\n  if (resolved.retry && typeof resolved.retry === 'object' && typeof resolved.retry.condition === 'function') {\n    logger.warn(\n      c.yellow('Warning: retry.condition function cannot be used inside a config file. '\n        + 'Use a RegExp pattern instead, or define the function in your test file.'),\n    )\n\n    resolved.retry = {\n      ...resolved.retry,\n      condition: undefined,\n    }\n  }\n\n  if (options.pool && typeof options.pool !== 'string') {\n    resolved.pool = options.pool.name","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/config/resolveConfig.ts#L204-L240","documentation":"Thrown during config resolution after a statSync on resolved.root returns no entry (or a non-directory). Vitest requires `test.root` (and the Vite root it derives from) to be an existing directory because that is where file discovery, transforms, and module resolution anchor. A missing or file-typed root is a hard failure.","triggerScenarios":"Setting `root` (or `test.root`) to a path that does not exist, is a file rather than a directory, or is a broken symlink. After deep-merging configDefaults with user options and assigning `resolved.root = viteConfig.root`, the code stats it; if `!rootStats?.isDirectory()`, it throws.","commonSituations":"Typo in the root path; root computed from a variable (env, dirname of a moved file) that is undefined/empty; running Vitest from a different cwd than expected; root pointing to a yet-to-be-created build output dir; monorepo where the package root was renamed.","solutions":["Verify the root path exists and is a directory: `ls -la <root>`.","Fix typos or make the root absolute and stable (e.g. `path.resolve(__dirname, 'src')`).","Ensure any build step that creates the root runs before Vitest.","If you moved/renamed a package, update `test.root` / `vite.root` accordingly."],"exampleFix":"// before\nexport default defineConfig({ test: { root: './srcc' } })\n// after\nexport default defineConfig({ test: { root: './src' } })","handlingStrategy":"validation","validationCode":"import { statSync } from 'node:fs'\nfunction assertRootDir(root: string) {\n  const s = statSync(root, { throwIfNoEntry: false })\n  if (!s?.isDirectory()) throw new Error(`root is not a directory: ${root}`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make test.root / vite.root absolute and stable (path.resolve(__dirname, 'src')).","Verify the directory exists before running Vitest, especially in CI after checkout.","Guard against undefined/empty roots computed from env or moved files."],"tags":[],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}