Skip to content

vite-node seems to incorrectly orders process.nextTick relative to microtasks #10

@Evilu

Description

@Evilu

Describe the bug

Description

vite-node does not respect Node.js's documented event loop ordering, specifically the guarantee that process.nextTick callbacks execute before other microtasks (Promises and queueMicrotask).

According to [Node.js documentation](https://nodejs.org/en/learn/asynchronous-work/understanding-processnexttick), process.nextTick callbacks should always be processed before the microtask queue. However, vite-node executes Promise and queueMicrotask callbacks before process.nextTick callbacks.

Reproduction

Expected Behavior

vite-node should maintain Node.js event loop ordering:

  1. Synchronous code ('S')
  2. process.nextTick queue ('N')
  3. Microtask queue - Promises and queueMicrotask ('P', 'Q')
  4. Timer phase ('T')
  5. Check phase ('I')

Actual Behavior

vite-node incorrectly executes in this order:

  1. Synchronous code ('S')
  2. Microtask queue ('P', 'Q')
  3. process.nextTick queue ('N') ❌ Should be before microtasks
  4. Check phase ('I')
  5. Timer phase ('T')

Impact

This breaks fundamental Node.js guarantees and can cause:

  • Race conditions in code relying on nextTick priority
  • Incompatibility when switching between node and vite-node
  • Unexpected behavior in timing-sensitive applications
  • Violation of Node.js event loop contracts that developers depend on

Reproduction

Create a file test.js: Promise.resolve().then(() => console.log('P')); queueMicrotask(() => console.log('Q')); process.nextTick(() => console.log('N')); setImmediate(() => console.log('I')); setTimeout(() => console.log('T')); console.log('S'); Run with Node.js and vite-node: bash $ node test.js S N P Q T I $ vite-node test.js S P Q N I T

System Info

- vite-node version: 3.2.4 (also reproduced on 5.0.0)
- Node.js version: tried with v22.21.1 v23.6.1 ,v25.1.0
- Operating System: macOS 26.0.1
- Package Manager: npm

Used Package Manager

npm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Contributions

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests (actually just go ahead and do it, thanks!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions