Registry / testing / p-queue

p-queue

JSON →
library9.3.0jsnpmunverified

Promise queue with concurrency control, version 9.3.0. Feature-complete library by Sindre Sorhus for rate-limiting async operations. Useful for REST API calls, CPU/memory intensive tasks, and batch processing. Supports concurrency limits, per-task timeouts, priority queuing, and rate limiting via interval caps. ESM-only since v7; requires Node.js >=20. Alternative to bottleneck, async.queue, or p-limit with richer scheduling features.

npm install p-queue
INSTALL
IMPORT
SIG · P-QUEUE
P
p-queue
testingjavascriptv9.3.0
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.

PQueue
import PQueue from 'p-queue'
const PQueue = require('p-queue')
ESM-only since v7; CommonJS require() will fail with ERR_REQUIRE_ESM.
PriorityQueue
import { PriorityQueue } from 'p-queue'
import PriorityQueue from 'p-queue/priority-queue'
Named export; path-based imports are not supported.
PQueue type
import PQueue from 'p-queue'
import { PQueue } from 'p-queue'
Default export is the class; named export PQueue does not exist. For types, use import PQueue from 'p-queue'.

Creates a queue with concurrency 2 and rate limit (5 requests/sec). Adds fetch tasks and waits for all results.

import PQueue from 'p-queue'; const queue = new PQueue({ concurrency: 2, interval: 1000, intervalCap: 5 }); async function fetchData(url) { const response = await fetch(url); return response.json(); } async function main() { const urls = ['https://api.example.com/1', 'https://api.example.com/2', 'https://api.example.com/3']; const results = await Promise.all(urls.map(url => queue.add(() => fetchData(url)))); console.log(results); } main().catch(console.error);
Debug
Known issues
breakingp-queue v7 is ESM-only. CommonJS require() will throw ERR_REQUIRE_ESM.
fix
Convert project to ESM or use v6 (CommonJS).
affects: >=7.0.0
breakingp-queue v7 drops Node.js <16 support. v9 requires Node.js >=20.
fix
Upgrade Node.js to >=20.
affects: >=9.0.0
deprecatedcustom ignore method is deprecated in v7+; implement via queueClass with priority.
fix
Use a custom PriorityQueue class with filter logic instead.
affects: >=7.0.0
gotchaDefault export is the class PQueue, not a factory function. Named export PQueue does not exist.
fix
Use `import PQueue from 'p-queue'`.
affects: >=1.0.0
gotchaTimeoutError is not exported; catch generic Error and check message.
fix
Use `if (error.message === 'Operation timed out')` or handle via rejection.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'p-queue'
Package not installed or wrong import path.
fix
Run `npm install p-queue` and ensure using ESM: `import PQueue from 'p-queue'`
ERR_REQUIRE_ESM: require() of ES Module
Using CommonJS require() with ESM-only package.
fix
Use `import` syntax or downgrade to p-queue v6 (but note v6 is older).
TypeError: queue.add is not a function
Incorrect import (e.g., destructuring non-existent export).
fix
Use default import: `import PQueue from 'p-queue'` then `new PQueue()`.
Queue.size is not a function
size is a getter property, not a method.
fix
Access `queue.size` instead of `queue.size()`.
Upgrade
Version history
9.3.0latest on npm
Audit
Dependencies
eventemitter3requiredPQueue extends EventEmitter3 for event handling (e.g., 'active', 'completed')
Agent activity
2 hits · last 30 days
node
2
Resources
p-queue — npm install p-queue · libregistry