{"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/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/integrations/vi.ts#L492-L528","documentation":"The user-facing `vi.useFakeTimers(config)` wrapper checks both the call-time `config.toFake` AND the global `fakeTimers.toFake` from Vitest config; if either includes `'nextTick'` while running inside a child process (`process.send` is set, i.e. the `forks` pool), it throws. This is the public-layer guard that complements the internal `FakeTimers` one, catching nextTick requests originating from global config too.","triggerScenarios":"Running under the `forks`/`child_process` pool with `fakeTimers.toFake` containing `'nextTick'` in `vitest.config.ts`, or calling `vi.useFakeTimers({ toFake: ['nextTick'] })` at runtime, while `process.send` exists.","commonSituations":"A repo-wide `fakeTimers.toFake` config that includes `nextTick` worked on one developer's `threads` setup but breaks in CI using `forks`; or enabling fake timers globally for all tests.","solutions":["Switch the pool to `threads` (`pool: 'threads'` in config or `--pool=threads`).","Remove `'nextTick'` from `fakeTimers.toFake` in config and from any runtime `vi.useFakeTimers({ toFake })` calls.","Scope nextTick mocking to specific tests under the threads pool rather than globally."],"exampleFix":"// before\n// vitest.config.ts\nexport default defineConfig({ test: { pool: 'forks', fakeTimers: { toFake: ['setTimeout', 'nextTick'] } } })\n// after\nexport default defineConfig({ test: { pool: 'threads', fakeTimers: { toFake: ['setTimeout', 'nextTick'] } } })","handlingStrategy":"validation","validationCode":"const isChild = typeof process !== 'undefined' && !!process.send\nconst globalToFake = (vitestConfig.test?.fakeTimers as any)?.toFake ?? []\nif (isChild && (config?.toFake ?? globalToFake).includes('nextTick')) {\n  throw new Error('use --pool=threads for nextTick faking')\n}","typeGuard":"function canUseNextTickFake(toFake: string[] = []): boolean {\n  const isChild = typeof process !== 'undefined' && !!process.send\n  return !isChild || !toFake.includes('nextTick')\n}","tryCatchPattern":null,"preventionTips":["Run nextTick-dependent timer tests under `pool: 'threads'`.","Keep `nextTick` out of global `fakeTimers.toFake` config."],"tags":["timers","fake-timers","forks-pool","nexttick","config"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}