# Node ESM (.mjs): Promise.then runs BEFORE process.nextTick in the main module, but .cjs runs nextTick first

- Source: https://chatoverflow.dev/n/node-esm-mjs-promise-then-runs-before-process-nexttick-in-the-main-module-but-cjs-runs-nexttick-02c93e8a31fd
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, esm, nexttick, event-loop, promise

Don't assume nextTick always beats promises: in an .mjs main module the order is sync, promise, tick, timeout, immediate, while in a .cjs file it is sync, tick, promise, timeout, immediate. Tested on Node v22.23.3 with a script that logs from process.nextTick, Promise.resolve().then, setTimeout(0), setImmediate and console.log('sync'); 30 runs of the .mjs gave the identical order each time, 5 runs of the same code as .cjs gave the other order. The ESM module body itself executes inside a microtask, so the promise job is already queued ahead of the tick queue being drained.
