Registry / devops / queue-microtask

queue-microtask

JSON →
library1.2.3jsnpmunverified

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-microtask
INSTALL
IMPORT
SIG · QUEUE-MICROTASK
Q
queue-microtask
devopsjavascriptv1.2.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

queueMicrotask
import queueMicrotask from 'queue-microtask'
const queueMicrotask = require('queue-microtask').default
Default export via ESM. In CommonJS, require returns the function directly; no .default needed.
default (require)
const queueMicrotask = require('queue-microtask')
const { queueMicrotask } = require('queue-microtask')
CommonJS require returns the function directly, not an object with a property.
default (ESM named import)
import queueMicrotask from 'queue-microtask'
import { queueMicrotask } from 'queue-microtask'
The package exports a single default function, not a named export. Named import fails at runtime.

Shows how to import and use queueMicrotask to schedule a microtask that runs after the current synchronous code.

const queueMicrotask = require('queue-microtask') function doSomething() { console.log('This runs after the current task') } queueMicrotask(doSomething) console.log('This runs first')
Debug
Known issues
deprecatedqueueMicrotask is deprecated in Node.js 12+
fix
Use the native globalThis.queueMicrotask in Node.js 12+ and modern browsers, or continue using this package for consistent behavior across older environments.
affects: >=1.0.0
gotchaThe package uses Promise.resolve().then() fallback in older environments, which may cause issues if Promise is not natively available (e.g., very old browsers without Promise polyfill).
fix
Ensure a Promise polyfill (e.g., es6-promise) is included if targeting environments without native Promise support.
affects: >=1.0.0
gotchaThe fallback to process.nextTick in Node.js 10 and earlier has different semantics: process.nextTick runs before I/O, while queueMicrotask (and Promise.then) run after I/O. For strict conformance, use native queueMicrotask where available.
fix
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.
affects: >=1.0.0
breakingVersion 1.0.0 removed support for CommonJS require in favor of ESM-only?
fix
The package still supports both ESM and CommonJS via a conditional export. Check the package.json exports field for details.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: queueMicrotask is not a function
Mis-imported the package, e.g., using named import instead of default import.
fix
Use default import: import queueMicrotask from 'queue-microtask' or const queueMicrotask = require('queue-microtask')
Cannot find module 'queue-microtask'
Package not installed.
fix
Run npm install queue-microtask
ReferenceError: queueMicrotask is not defined
Using native queueMicrotask in an environment that doesn't support it (e.g., older Node.js or browser) without the polyfill.
fix
Install and import the queue-microtask package, then use its export instead of globalThis.queueMicrotask.
Upgrade
Version history
1.2.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
queue-microtask — npm install queue-microtask · libregistry