{"record":{"id":"760541c5bf75225c","repo":"vitest-dev/vitest","slug":"vi-usefaketimers-tofake-nexttick-is-not","errorCode":null,"errorMessage":"vi.useFakeTimers({ toFake: [\"nextTick\"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.","messagePattern":"vi\\.useFakeTimers\\((.+?)\\) is not supported in node:child_process\\. Use --pool=threads if mocking nextTick is required\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/integrations/vi.ts","lineNumber":510,"sourceCode":"      config: state().config.fakeTimers,\n    }))\n\n  const _stubsGlobal = new Map<\n    string | symbol | number,\n    PropertyDescriptor | undefined\n  >()\n  const _stubsEnv = new Map()\n\n  const _envBooleans = ['PROD', 'DEV', 'SSR']\n\n  const utils: VitestUtils = {\n    useFakeTimers(config?: FakeTimersConfig) {\n      if (isChildProcess()) {\n        if (\n          config?.toFake?.includes('nextTick')\n          || state().config?.fakeTimers?.toFake?.includes('nextTick')\n        ) {\n          throw new Error(\n            'vi.useFakeTimers({ toFake: [\"nextTick\"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.',\n          )\n        }\n      }\n\n      if (config) {\n        timers().configure({ ...state().config.fakeTimers, ...config })\n      }\n      else {\n        timers().configure(state().config.fakeTimers)\n      }\n\n      timers().useFakeTimers()\n      return utils\n    },\n\n    isFakeTimers() {\n      return timers().isFakeTimers()","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/integrations/vi.ts#L492-L528","documentation":"Thrown by `vi.useFakeTimers(config)` when running inside a child process (default `forks` pool) and either the passed `config.toFake` or the global `fakeTimers.toFake` config includes `nextTick`. This duplicates the FakeTimers-level guard (error 181) at the public API boundary with a more actionable message directing the user to `--pool=threads`. Mocking `nextTick` in a forked child process deadlocks Node internals.","triggerScenarios":"Calling `vi.useFakeTimers({ toFake: ['nextTick', ...] })` while running with the `forks` pool; setting `fakeTimers: { toFake: ['nextTick'] }` in the Vitest config and running the default (forks) pool; enabling nextTick globally via config and then calling `vi.useFakeTimers()` without overriding `toFake`.","commonSituations":"Copying a Jest config that mocked nextTick; project-wide `toFake` setting that includes nextTick combined with the default pool; enabling nextTick to flush microtasks in async tests.","solutions":["Run with `--pool=threads` (or set `pool: 'threads'` in config) so nextTick can be mocked safely.","Remove `nextTick` from `toFake` in both the call and the `fakeTimers` config.","Mock `queueMicrotask`/`setTimeout` instead, or restructure the test to avoid nextTick-dependent timing."],"exampleFix":"// before\nvi.useFakeTimers({ toFake: ['setTimeout', 'nextTick'] })\n\n// after\nvi.useFakeTimers({ toFake: ['setTimeout'] })\n// or: vitest run --pool=threads","handlingStrategy":"validation","validationCode":"function useFakeTimersSafe(cfg) {\n  const includesNextTick = cfg?.toFake?.includes('nextTick')\n  const child = typeof process !== 'undefined' && !!process.send\n  if (includesNextTick && child) {\n    throw new Error('use --pool=threads to mock nextTick')\n  }\n  return vi.useFakeTimers(cfg)\n}","typeGuard":"function isChildProcess() {\n  return typeof process !== 'undefined' && !!process.send\n}","tryCatchPattern":null,"preventionTips":["Do not include 'nextTick' in toFake when using the forks pool.","Keep fakeTimers.toFake free of nextTick in shared config, or pin pool: 'threads'.","Document the pool choice in CI so contributors know the constraint."],"tags":["fake-timers","nexttick","child-process","pool-config","vi"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}