{"record":{"id":"d5337d8dc77e3bff","repo":"vitest-dev/vitest","slug":"process-nexttick-cannot-be-mocked-inside-child-pro","errorCode":null,"errorMessage":"process.nextTick cannot be mocked inside child_process","messagePattern":"process\\.nextTick cannot be mocked inside child_process","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/integrations/mock/timers.ts","lineNumber":161,"sourceCode":"      this._clock.uninstall()\n      this._fakingTime = false\n    }\n  }\n\n  useFakeTimers(): void {\n    const fakeDate = this._fakingDate || Date.now()\n    if (this._fakingDate) {\n      this._clock.uninstall()\n      this._fakingDate = null\n    }\n\n    if (this._fakingTime) {\n      this._clock.uninstall()\n    }\n\n    let toFake = this._userConfig?.toFake\n    if (isChildProcess() && toFake?.includes('nextTick')) {\n      throw new Error(\n        'process.nextTick cannot be mocked inside child_process',\n      )\n    }\n\n    let toNotFake = this._userConfig?.toNotFake\n    if (toFake === undefined && toNotFake === undefined) {\n      // Do not mock timers internally used by node by default. It can still be mocked through userConfig.\n      toFake = (Object.keys(this._fakeTimers.timers) as FakeMethod[])\n        .filter(timer => timer !== 'nextTick' && timer !== 'queueMicrotask')\n    }\n    if (isChildProcess() && toNotFake && !toNotFake.includes('nextTick')) {\n      toNotFake = [...toNotFake, 'nextTick']\n    }\n\n    this._clock = this._fakeTimers.install({\n      now: fakeDate,\n      ...this._userConfig,\n      ...(toFake && { toFake }),","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/integrations/mock/timers.ts#L143-L179","documentation":"Raised by `FakeTimers.useFakeTimers()` when Vitest detects it is running inside a Node `child_process` and the user's `toFake` list explicitly includes `nextTick`. Mocking `process.nextTick` inside a child process (the default `forks` pool) breaks Node internals, so Vitest forbids it. The guard runs before installing the sinon fake clock.","triggerScenarios":"Setting `fakeTimers.toFake` in config (or calling `vi.useFakeTimers({ toFake: ['nextTick'] })` via the timers API) to include `nextTick` while the active pool is `forks` (child_process). Reached when the FakeTimers class itself is driven directly with a config that includes `nextTick`.","commonSituations":"Migrating from Jest where nextTick mocking was allowed; copying a `toFake` array from a threads-pool project into a forks-pool project; explicitly enabling `nextTick` to flush microtasks in tests.","solutions":["Remove `nextTick` from the `toFake` array in `vi.useFakeTimers(...)` or in `test.fakeTimers.toFake` config.","Switch the pool to threads: `--pool=threads` (or `pool: 'threads'` in config) if you must mock nextTick.","Mock `queueMicrotask`/`setTimeout` instead, or restructure the test to avoid relying on nextTick scheduling."],"exampleFix":"// before\nvi.useFakeTimers({ toFake: ['setTimeout', 'nextTick'] })\n\n// after (forks pool)\nvi.useFakeTimers({ toFake: ['setTimeout'] })\n// or run with --pool=threads and keep nextTick","handlingStrategy":"validation","validationCode":"function safeUseFakeTimers(cfg) {\n  if (cfg?.toFake?.includes('nextTick') && isChildProcessLike()) {\n    throw new Error('nextTick mocking requires --pool=threads')\n  }\n  return vi.useFakeTimers(cfg)\n}","typeGuard":"function isChildProcessLike() {\n  return typeof process !== 'undefined' && !!process.send // forked child has process.send\n}","tryCatchPattern":null,"preventionTips":["Do not include 'nextTick' in fakeTimers.toFake when using the forks/child_process pool.","Document the pool choice in CI config so contributors know nextTick mocking is off-limits.","Prefer queueMicrotask/setTimeout mocking or run with --pool=threads when nextTick fidelity is required."],"tags":["fake-timers","nexttick","child-process","pool-config"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}