A fast, tiny polyfill for the WHATWG queueMicrotask function for modern JavaScript engines. Current stable version is 1.2.3, with infrequent releases. It provides a standardized microtask queuing mechanism (equivalent to Promise.resolve().then(fn)) in all modern browsers and Node.js, with zero dependencies and under 10 lines of code. Unlike heavier alternatives like immediate or asap, it prioritizes small bundle size and uses native queueMicrotask where available, falling back to Promise.resolve().then() in older environments.
npm install queue-microtaskNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to import and use queueMicrotask to schedule a microtask that runs after the current synchronous code.
Use the native globalThis.queueMicrotask in Node.js 12+ and modern browsers, or continue using this package for consistent behavior across older environments.
Ensure a Promise polyfill (e.g., es6-promise) is included if targeting environments without native Promise support.
If exact microtask timing is critical, consider using native queueMicrotask when available and only falling back to this shim in browsers or older Node versions without native support.
The package still supports both ESM and CommonJS via a conditional export. Check the package.json exports field for details.
Use default import: import queueMicrotask from 'queue-microtask' or const queueMicrotask = require('queue-microtask')Run npm install queue-microtask
Install and import the queue-microtask package, then use its export instead of globalThis.queueMicrotask.
No dependency data recorded yet.