{"record":{"id":"24b7896c70baabf3","repo":"vitest-dev/vitest","slug":"cache-dir-is-deprecated","errorCode":null,"errorMessage":"--cache.dir is deprecated","messagePattern":"--cache\\.dir is deprecated","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/cli/cli-config.ts","lineNumber":772,"sourceCode":"      'Threshold in milliseconds for a test or suite to be considered slow (default: `300`)',\n    argument: '<threshold>',\n  },\n  teardownTimeout: {\n    description:\n      'Default timeout of a teardown function in milliseconds (default: `10000`)',\n    argument: '<timeout>',\n  },\n  cache: {\n    description: 'Enable cache',\n    argument: '', // allow only boolean\n    subcommands: {\n      dir: null,\n    },\n    default: true,\n    // cache can only be \"false\" or an object\n    transform(cache) {\n      if (typeof cache !== 'boolean' && cache) {\n        throw new Error('--cache.dir is deprecated')\n      }\n      if (cache) {\n        return {}\n      }\n      return cache\n    },\n  },\n  maxConcurrency: {\n    description: 'Maximum number of concurrent tests and suites during test file execution (default: `5`)',\n    argument: '<number>',\n  },\n  fsModuleCache: {\n    description: 'Cache transformed modules on the file system and reuse them between reruns (default: `false`)',\n  },\n  fsModuleCachePath: {\n    description: 'Directory where the `fsModuleCache` is stored (default: `node_modules/.vitest-cache`)',\n    argument: '<path>',\n  },","sourceCodeStart":754,"sourceCodeEnd":790,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/cli/cli-config.ts#L754-L790","documentation":"`--cache.dir` was removed in Vitest 4. The `cache` option is now only a boolean (`true`/`false`) or an empty object; passing a non-boolean truthy value (such as `{ dir: '...' }`) trips the `transform` and reports the deprecation as a hard error.","triggerScenarios":"Calling `vitest --cache.dir=.cache`, providing `test: { cache: { dir: './.vitest' } }` in config, or merging an old config that still sets `cache.dir`. The check is `typeof cache !== 'boolean' && cache`.","commonSituations":"Upgrading from Vitest 3 (or earlier) where `cache.dir` was valid; a shared config preset that has not been updated; tooling (Nx, Turborepo generators) emitting the v3 shape.","solutions":["Remove `cache.dir` from CLI and config; let Vitest use its default cache location.","Set `test.cache` to a boolean: `cache: true` (or omit) / `cache: false`.","If you need to relocate the cache, set the appropriate environment/Temp dir or open a feature request rather than reusing the removed key."],"exampleFix":"// before (v3)\nexport default defineConfig({ test: { cache: { dir: './.vitest' } } })\n\n// after (v4)\nexport default defineConfig({ test: { cache: true } })","handlingStrategy":"validation","validationCode":"import type { InlineConfig } from 'vitest/config'\n\nfunction migrateCache(cfg: any): InlineConfig['test'] {\n  if (cfg?.test?.cache && typeof cfg.test.cache === 'object' && 'dir' in cfg.test.cache) {\n    console.warn('test.cache.dir was removed in Vitest 4; ignoring.')\n    return { ...cfg.test, cache: true }\n  }\n  return cfg.test\n}","typeGuard":"function isV4CacheShape(cache: unknown): cache is boolean {\n  return cache === undefined || typeof cache === 'boolean' || cache === null\n}","tryCatchPattern":null,"preventionTips":["After a Vitest 3→4 upgrade, grep configs for `cache.dir` and `workspace`.","Treat `test.cache` as boolean-only in shared presets.","Pin and read the v4 migration guide before bumping the major."],"tags":["cli","config","cache","deprecation","vitest-4","migration"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}