-
-
Notifications
You must be signed in to change notification settings - Fork 11
Description
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:
- Synchronous code ('S')
- process.nextTick queue ('N')
- Microtask queue - Promises and queueMicrotask ('P', 'Q')
- Timer phase ('T')
- Check phase ('I')
Actual Behavior
vite-node incorrectly executes in this order:
- Synchronous code ('S')
- Microtask queue ('P', 'Q')
- process.nextTick queue ('N') ❌ Should be before microtasks
- Check phase ('I')
- 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: npmUsed 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!)